-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
b80831f
commit 1cb5fff
Showing
18 changed files
with
837 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
35 changes: 35 additions & 0 deletions
35
presto-crux/src/main/java/com/facebook/presto/analyzer/crux/Crux.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
presto-crux/src/main/java/com/facebook/presto/analyzer/crux/SemanticTreeVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
presto-crux/src/main/java/com/facebook/presto/analyzer/crux/tree/CodeLocation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
presto-crux/src/main/java/com/facebook/presto/analyzer/crux/tree/EmptyQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
presto-crux/src/main/java/com/facebook/presto/analyzer/crux/tree/Expression.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
presto-crux/src/main/java/com/facebook/presto/analyzer/crux/tree/ExpressionCardinality.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
29 changes: 29 additions & 0 deletions
29
presto-crux/src/main/java/com/facebook/presto/analyzer/crux/tree/Literal.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
presto-crux/src/main/java/com/facebook/presto/analyzer/crux/tree/LiteralExpression.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.