Skip to content

Commit

Permalink
[v1] Add defaults for AstVisitor; port partiql-ast normalization pass…
Browse files Browse the repository at this point in the history
…es to partiql-planner
  • Loading branch information
alancai98 committed Oct 30, 2024
1 parent f0569bd commit 23c1a3c
Show file tree
Hide file tree
Showing 25 changed files with 2,352 additions and 538 deletions.
372 changes: 268 additions & 104 deletions partiql-ast/api/partiql-ast.api

Large diffs are not rendered by default.

758 changes: 758 additions & 0 deletions partiql-ast/src/main/java/org/partiql/ast/v1/AstRewriter.kt

Large diffs are not rendered by default.

740 changes: 545 additions & 195 deletions partiql-ast/src/main/java/org/partiql/ast/v1/AstVisitor.java

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions partiql-ast/src/main/java/org/partiql/ast/v1/ExcludeStep.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.partiql.ast.v1;

import lombok.Builder;
import lombok.EqualsAndHashCode;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
Expand All @@ -15,6 +16,7 @@ public abstract class ExcludeStep extends AstNode {
* TODO docs, equals, hashcode
*/
@Builder(builderClassName = "Builder")
@EqualsAndHashCode(callSuper = false)
public static class StructField extends ExcludeStep {
@NotNull
public final Identifier symbol;
Expand All @@ -41,6 +43,7 @@ public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) {
* TODO docs, equals, hashcode
*/
@Builder(builderClassName = "Builder")
@EqualsAndHashCode(callSuper = false)
public static class CollIndex extends ExcludeStep {
public final int index;

Expand All @@ -64,6 +67,7 @@ public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) {
* TODO docs, equals, hashcode
*/
@Builder(builderClassName = "Builder")
@EqualsAndHashCode(callSuper = false)
public static class StructWildcard extends ExcludeStep {
@NotNull
@Override
Expand All @@ -81,6 +85,7 @@ public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) {
* TODO docs, equals, hashcode
*/
@Builder(builderClassName = "Builder")
@EqualsAndHashCode(callSuper = false)
public static class CollWildcard extends ExcludeStep {
@NotNull
@Override
Expand Down
15 changes: 1 addition & 14 deletions partiql-ast/src/main/java/org/partiql/ast/v1/FromTableRef.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
package org.partiql.ast.v1;

import org.jetbrains.annotations.NotNull;

/**
* TODO docs, equals, hashcode
*/
public abstract class FromTableRef extends AstNode {
@Override
public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) {
if (this instanceof FromExpr) {
return visitor.visitFromExpr((FromExpr) this, ctx);
} else if (this instanceof FromJoin) {
return visitor.visitFromJoin((FromJoin) this, ctx);
} else {
throw new IllegalStateException("Unexpected value: " + this);
}
}
}
public abstract class FromTableRef extends AstNode {}
19 changes: 1 addition & 18 deletions partiql-ast/src/main/java/org/partiql/ast/v1/Select.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
package org.partiql.ast.v1;

import org.jetbrains.annotations.NotNull;

/**
* TODO docs, equals, hashcode
*/
public abstract class Select extends AstNode {
@Override
public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) {
if (this instanceof SelectStar) {
return visitor.visitSelectStar((SelectStar) this, ctx);
} else if (this instanceof SelectList) {
return visitor.visitSelectList((SelectList) this, ctx);
} else if (this instanceof SelectPivot) {
return visitor.visitSelectPivot((SelectPivot) this, ctx);
} else if (this instanceof SelectValue) {
return visitor.visitSelectValue((SelectValue) this, ctx);
} else {
throw new IllegalStateException("Unexpected value: " + this);
}
}
}
public abstract class Select extends AstNode {}
11 changes: 0 additions & 11 deletions partiql-ast/src/main/java/org/partiql/ast/v1/SelectItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,6 @@
* TODO docs, equals, hashcode
*/
public abstract class SelectItem extends AstNode {
@Override
public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) {
if (this instanceof Star) {
return visitor.visitSelectItemStar((Star) this, ctx);
} else if (this instanceof Expr) {
return visitor.visitSelectItemExpr((Expr) this, ctx);
} else {
throw new IllegalStateException("Unexpected value: " + this);
}
}

/**
* TODO docs, equals, hashcode
*/
Expand Down
15 changes: 1 addition & 14 deletions partiql-ast/src/main/java/org/partiql/ast/v1/Statement.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
package org.partiql.ast.v1;

import org.jetbrains.annotations.NotNull;

/**
* TODO docs, equals, hashcode
*/
public abstract class Statement extends AstNode {
@Override
public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) {
if (this instanceof Query) {
return visitor.visitQuery((Query) this, ctx);
} else if (this instanceof Explain) {
return visitor.visitExplain((Explain) this, ctx);
} else {
throw new IllegalStateException("Unexpected value: " + this);
}
}
}
public abstract class Statement extends AstNode {}
73 changes: 1 addition & 72 deletions partiql-ast/src/main/java/org/partiql/ast/v1/expr/Expr.java
Original file line number Diff line number Diff line change
@@ -1,79 +1,8 @@
package org.partiql.ast.v1.expr;

import org.jetbrains.annotations.NotNull;
import org.partiql.ast.v1.AstNode;
import org.partiql.ast.v1.AstVisitor;

/**
* TODO docs, equals, hashcode
*/
public abstract class Expr extends AstNode {
@Override
public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) {
if (this instanceof ExprLit) {
return visitor.visitExprLit((ExprLit) this, ctx);
} else if (this instanceof ExprVariant) {
return visitor.visitExprVariant((ExprVariant) this, ctx);
} else if (this instanceof ExprVarRef) {
return visitor.visitExprVarRef((ExprVarRef) this, ctx);
} else if (this instanceof ExprSessionAttribute) {
return visitor.visitExprSessionAttribute((ExprSessionAttribute) this, ctx);
} else if (this instanceof ExprPath) {
return visitor.visitExprPath((ExprPath) this, ctx);
} else if (this instanceof ExprCall) {
return visitor.visitExprCall((ExprCall) this, ctx);
} else if (this instanceof ExprParameter) {
return visitor.visitExprParameter((ExprParameter) this, ctx);
} else if (this instanceof ExprOperator) {
return visitor.visitExprOperator((ExprOperator) this, ctx);
} else if (this instanceof ExprNot) {
return visitor.visitExprNot((ExprNot) this, ctx);
} else if (this instanceof ExprAnd) {
return visitor.visitExprAnd((ExprAnd) this, ctx);
} else if (this instanceof ExprOr) {
return visitor.visitExprOr((ExprOr) this, ctx);
} else if (this instanceof ExprValues) {
return visitor.visitExprValues((ExprValues) this, ctx);
} else if (this instanceof ExprArray) {
return visitor.visitExprArray((ExprArray) this, ctx);
} else if (this instanceof ExprBag) {
return visitor.visitExprBag((ExprBag) this, ctx);
} else if (this instanceof ExprStruct) {
return visitor.visitExprStruct((ExprStruct) this, ctx);
} else if (this instanceof ExprLike) {
return visitor.visitExprLike((ExprLike) this, ctx);
} else if (this instanceof ExprBetween) {
return visitor.visitExprBetween((ExprBetween) this, ctx);
} else if (this instanceof ExprInCollection) {
return visitor.visitExprInCollection((ExprInCollection) this, ctx);
} else if (this instanceof ExprIsType) {
return visitor.visitExprIsType((ExprIsType) this, ctx);
} else if (this instanceof ExprCase) {
return visitor.visitExprCase((ExprCase) this, ctx);
} else if (this instanceof ExprCoalesce) {
return visitor.visitExprCoalesce((ExprCoalesce) this, ctx);
} else if (this instanceof ExprNullIf) {
return visitor.visitExprNullIf((ExprNullIf) this, ctx);
} else if (this instanceof ExprSubstring) {
return visitor.visitExprSubstring((ExprSubstring) this, ctx);
} else if (this instanceof ExprPosition) {
return visitor.visitExprPosition((ExprPosition) this, ctx);
} else if (this instanceof ExprTrim) {
return visitor.visitExprTrim((ExprTrim) this, ctx);
} else if (this instanceof ExprOverlay) {
return visitor.visitExprOverlay((ExprOverlay) this, ctx);
} else if (this instanceof ExprExtract) {
return visitor.visitExprExtract((ExprExtract) this, ctx);
} else if (this instanceof ExprCast) {
return visitor.visitExprCast((ExprCast) this, ctx);
} else if (this instanceof ExprQuerySet) {
return visitor.visitExprQuerySet((ExprQuerySet) this, ctx);
} else if (this instanceof ExprMatch) {
return visitor.visitExprMatch((ExprMatch) this, ctx);
} else if (this instanceof ExprWindow) {
return visitor.visitExprWindow((ExprWindow) this, ctx);
} else {
throw new IllegalStateException("Unexpected value: " + this);
}
}
}
public abstract class Expr extends AstNode {}
17 changes: 0 additions & 17 deletions partiql-ast/src/main/java/org/partiql/ast/v1/graph/GraphLabel.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,6 @@
* TODO docs, equals, hashcode
*/
public abstract class GraphLabel extends AstNode {
@Override
public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) {
if (this instanceof Name) {
return visitor.visitGraphLabelName((Name) this, ctx);
} else if (this instanceof Wildcard) {
return visitor.visitGraphLabelWildcard((Wildcard) this, ctx);
} else if (this instanceof Negation) {
return visitor.visitGraphLabelNegation((Negation) this, ctx);
} else if (this instanceof Conj) {
return visitor.visitGraphLabelConj((Conj) this, ctx);
} else if (this instanceof Disj) {
return visitor.visitGraphLabelDisj((Disj) this, ctx);
} else {
throw new IllegalStateException("Unexpected value: " + this);
}
}

/**
* TODO docs, equals, hashcode
*/
Expand Down
13 changes: 0 additions & 13 deletions partiql-ast/src/main/java/org/partiql/ast/v1/graph/GraphPart.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,6 @@
* TODO docs, equals, hashcode
*/
public abstract class GraphPart extends AstNode {
@Override
public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) {
if (this instanceof Node) {
return visitor.visitGraphPartNode((Node) this, ctx);
} else if (this instanceof Edge) {
return visitor.visitGraphPartEdge((Edge) this, ctx);
} else if (this instanceof Pattern) {
return visitor.visitGraphPartPattern((Pattern) this, ctx);
} else {
throw new IllegalStateException("Unexpected value: " + this);
}
}

/**
* TODO docs, equals, hashcode
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ public Collection<AstNode> children() {

@Override
public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) {
return visitor.visitGraphMatchPattern(this, ctx);
return visitor.visitGraphPattern(this, ctx);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,6 @@
* TODO docs, equals, hashcode
*/
public abstract class GraphSelector extends AstNode {
@Override
public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) {
if (this instanceof AnyShortest) {
return visitor.visitGraphSelectorAnyShortest((AnyShortest) this, ctx);
} else if (this instanceof AllShortest) {
return visitor.visitGraphSelectorAllShortest((AllShortest) this, ctx);
} else if (this instanceof Any) {
return visitor.visitGraphSelectorAny((Any) this, ctx);
} else if (this instanceof AnyK) {
return visitor.visitGraphSelectorAnyK((AnyK) this, ctx);
} else if (this instanceof ShortestK) {
return visitor.visitGraphSelectorShortestK((ShortestK) this, ctx);
} else if (this instanceof ShortestKGroup) {
return visitor.visitGraphSelectorShortestKGroup((ShortestKGroup) this, ctx);
} else {
throw new IllegalStateException("Unexpected value: " + this);
}
}

/**
* TODO docs, equals, hashcode
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import org.partiql.ast.builder.ast
import org.partiql.value.PartiQLValueExperimental
import org.partiql.value.StringValue

// TODO DELETE FILE

private val col = { index: () -> Int -> "_${index()}" }

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ package org.partiql.ast.normalize

import org.partiql.ast.Statement

// TODO DELETE FILE

/**
* Wraps a rewriter with a default entry point.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ package org.partiql.ast.normalize

import org.partiql.ast.Statement

// TODO DELETE FILE

/**
* AST normalization
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import org.partiql.ast.fromJoin
import org.partiql.ast.helpers.toBinder
import org.partiql.ast.util.AstRewriter

// TODO DELETE FILE

/**
* Assign aliases to any FROM source which does not have one.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import org.partiql.ast.groupByKey
import org.partiql.ast.helpers.toBinder
import org.partiql.ast.util.AstRewriter

// TODO DELETE FILE

/**
* Adds a unique binder to each group key.
*/
Expand Down
Loading

0 comments on commit 23c1a3c

Please sign in to comment.