Skip to content

Commit

Permalink
Add dummy crux analyzer
Browse files Browse the repository at this point in the history
Adding dummy crux analyzer. This would eventually be replaced by real
implementation. The current dummy analyzer is added to enable
development and testing.
  • Loading branch information
jainxrohit committed Dec 2, 2022
1 parent b80831f commit 1cb5fff
Show file tree
Hide file tree
Showing 18 changed files with 837 additions and 0 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
<module>presto-atop</module>
<module>presto-spi</module>
<module>presto-analyzer</module>
<module>presto-crux</module>
<module>presto-cache</module>
<module>presto-jmx</module>
<module>presto-record-decoder</module>
Expand Down
25 changes: 25 additions & 0 deletions presto-crux/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.facebook.presto</groupId>
<artifactId>presto-root</artifactId>
<version>0.279-SNAPSHOT</version>
</parent>

<artifactId>presto-crux</artifactId>
<description>Presto crux analyzer</description>

<properties>
<air.main.basedir>${project.parent.basedir}</air.main.basedir>
</properties>

<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.facebook.presto.analyzer.crux;

import com.facebook.presto.analyzer.crux.tree.EmptyQuery;
import com.facebook.presto.analyzer.crux.tree.SemanticTree;

/**
* TODO: A dummy implementation of Crux analyzer. This would be replaced with actual implementation.
*/
public class Crux
{
private Crux()
{
}

/**
* // TODO: Returning an empty query for now, this should be replaced with actual crux call
*/
public static SemanticTree sqlToTree(String query)
{
return new EmptyQuery(null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.facebook.presto.analyzer.crux;

import com.facebook.presto.analyzer.crux.tree.EmptyQuery;
import com.facebook.presto.analyzer.crux.tree.Expression;
import com.facebook.presto.analyzer.crux.tree.LiteralExpression;
import com.facebook.presto.analyzer.crux.tree.Query;
import com.facebook.presto.analyzer.crux.tree.SelectItem;
import com.facebook.presto.analyzer.crux.tree.SelectQuery;
import com.facebook.presto.analyzer.crux.tree.SemanticTree;
import com.facebook.presto.analyzer.crux.tree.Statement;

/**
* TODO: A dummy implementation of Crux analyzer visitor. This would be replaced with actual implementation.
* At the moment this visitor only has limited classes as we need to enable development.
*/
public abstract class SemanticTreeVisitor
{
public void visitEmptyQuery(EmptyQuery node)
{
}

public void visitExpression(Expression node)
{
switch (node.getExpressionKind()) {
case LiteralExpression:
visitLiteralExpression(node.asLiteralExpression());
break;
default:
throw new UnsupportedOperationException("Missing case: " + node.getExpressionKind().name());
}
}

public void visitLiteralExpression(LiteralExpression node)
{
}

public void visitQuery(Query node)
{
switch (node.getQueryKind()) {
case EmptyQuery:
visitEmptyQuery(node.asEmptyQuery());
break;
case SelectQuery:
visitSelectQuery(node.asSelectQuery());
break;
default:
throw new UnsupportedOperationException("Missing case: " + node.getQueryKind().name());
}
}

public void visitSelectItem(SelectItem node)
{
visitExpression(node.getValue());
}

public void visitSelectQuery(SelectQuery node)
{
visitQuery(node.getQuery());
for (SelectItem item : node.getSelectItems()) {
visitSelectItem(item);
}
}

public void visitSemanticTree(SemanticTree node)
{
switch (node.getSemanticTreeKind()) {
case Expression:
visitExpression(node.asExpression());
break;
case Statement:
visitStatement(node.asStatement());
break;
default:
throw new UnsupportedOperationException("Missing case: " + node.getSemanticTreeKind().name());
}
}

public void visitStatement(Statement node)
{
switch (node.getStatementKind()) {
case Query:
visitQuery(node.asQuery());
break;
default:
throw new UnsupportedOperationException("Missing case: " + node.getStatementKind().name());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.facebook.presto.analyzer.crux.tree;

public class CodeLocation
{
private final int lineNumber;
private final int columnNumber;

public CodeLocation(int lineNumber, int columnNumber)
{
this.lineNumber = lineNumber;
this.columnNumber = columnNumber;
}

public int getLineNumber()
{
return lineNumber;
}

public int getColumnNumber()
{
return columnNumber;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.facebook.presto.analyzer.crux.tree;

public class EmptyQuery
extends Query
{
public EmptyQuery(CodeLocation location)
{
super(Kind.EmptyQuery, location);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.facebook.presto.analyzer.crux.tree;

import static java.util.Objects.requireNonNull;

public class Expression
extends SemanticTree
{
private final Kind kind;
private final Type type;
private final ExpressionCardinality cardinality;

public Expression(Kind kind,
CodeLocation location,
Type type,
ExpressionCardinality cardinality)
{
super(SemanticTree.Kind.Expression, location);
this.kind = requireNonNull(kind, "expression kind is null");
this.type = requireNonNull(type, "type is null");
this.cardinality = requireNonNull(cardinality, "cardinality is null");
}

public Kind getExpressionKind()
{
return this.kind;
}

public Type getType()
{
return type;
}

public ExpressionCardinality getCardinality()
{
return cardinality;
}

public boolean isLiteralExpression()
{
return this instanceof LiteralExpression;
}

public LiteralExpression asLiteralExpression()
{
return (LiteralExpression) this;
}

public enum Kind
{
LiteralExpression
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.facebook.presto.analyzer.crux.tree;

public enum ExpressionCardinality {
SCALAR
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.facebook.presto.analyzer.crux.tree;

public class Literal
{
private final String value;

public Literal(String value)
{
this.value = value;
}

public String getValue()
{
return value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.facebook.presto.analyzer.crux.tree;

import static java.util.Objects.requireNonNull;

public class LiteralExpression
extends Expression
{
private final Literal value;
private final String text;

public LiteralExpression(
CodeLocation location,
Type type,
ExpressionCardinality cardinality,
Literal value,
String text)
{
super(Expression.Kind.LiteralExpression, location, type, cardinality);
this.value = requireNonNull(value, "value is null");
this.text = requireNonNull(text, "text is null");
}

public Literal getValue()
{
return value;
}

public String getText()
{
return text;
}
}
Loading

0 comments on commit 1cb5fff

Please sign in to comment.