-
Notifications
You must be signed in to change notification settings - Fork 63
Adds parsing and modeling of CTEs #1736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
af0995b
Adds parsing and ast modeling for CTEs
johnedquinn 7f0b848
Adds planning error for the with clause
johnedquinn 3eeb520
Reverts the changing of the development test
johnedquinn 2edcd74
Addresses PR feedback
johnedquinn 216a29f
Updates AstRewriter, NormalizeSelect, and tests for isRecursive
johnedquinn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,73 @@ | ||
package org.partiql.ast; | ||
|
||
import lombok.Builder; | ||
import lombok.EqualsAndHashCode; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* <p> | ||
* Represents a PartiQL WITH clause. | ||
* </p> | ||
* <p>{@code <with clause> ::= WITH [ RECURSIVE ] <with list>}</p> | ||
* <p>{@code <with list> ::= <with list element> [ { <comma> <with list element> }... ]}</p> | ||
* @see WithListElement | ||
* @see org.partiql.ast.expr.ExprQuerySet | ||
*/ | ||
@Builder(builderClassName = "Builder") | ||
@EqualsAndHashCode(callSuper = false) | ||
public final class With extends AstNode { | ||
|
||
@NotNull | ||
private final List<WithListElement> elements; | ||
|
||
private final boolean isRecursive; | ||
|
||
/** | ||
* Creates a new WITH clause with the specified elements and RECURSIVE set to the specified value. | ||
* @param elements the list of WITH list elements | ||
* @param isRecursive true if this WITH clause specified RECURSIVE; | ||
*/ | ||
public With(@NotNull List<WithListElement> elements, boolean isRecursive) { | ||
this.elements = elements; | ||
this.isRecursive = isRecursive; | ||
} | ||
|
||
/** | ||
* Creates a new WITH clause with the specified elements and RECURSIVE set to false. | ||
* @param elements the list of WITH list elements | ||
*/ | ||
public With(@NotNull List<WithListElement> elements) { | ||
this(elements, false); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public List<AstNode> getChildren() { | ||
return new ArrayList<>(elements); | ||
} | ||
|
||
@Override | ||
public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) { | ||
return visitor.visitWith(this, ctx); | ||
} | ||
|
||
/** | ||
* Returns the list of WITH list elements. | ||
* @return the list of WITH list elements | ||
*/ | ||
@NotNull | ||
public List<WithListElement> getElements() { | ||
return this.elements; | ||
} | ||
|
||
/** | ||
* Returns whether this WITH clause specified RECURSIVE. | ||
* @return whether this WITH clause specified RECURSIVE. | ||
*/ | ||
public boolean isRecursive() { | ||
return this.isRecursive; | ||
} | ||
} |
109 changes: 109 additions & 0 deletions
109
partiql-ast/src/main/java/org/partiql/ast/WithListElement.java
This file contains hidden or 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,109 @@ | ||
package org.partiql.ast; | ||
|
||
import lombok.Builder; | ||
import lombok.EqualsAndHashCode; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.partiql.ast.expr.ExprQuerySet; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* <p> | ||
* Represents a {@code <with list element>}. | ||
* </p> | ||
* <p> | ||
* {@code | ||
* <with list element> ::= | ||
* <query name> | ||
* [ <left paren> <with column list> <right paren> ] | ||
* AS <left paren> <query expression> <right paren> | ||
* [ <search or cycle clause> ] | ||
* } | ||
* </p> | ||
* <p>{@code <with column list> ::= <column name list>}</p> | ||
* <p>{@code <column name list> ::= <column name> [ { <comma> <column name> }... ]}</p> | ||
* <p>{@code <column name> ::= <identifier>}</p> | ||
* @see With | ||
* @see ExprQuerySet | ||
*/ | ||
@Builder(builderClassName = "Builder") | ||
@EqualsAndHashCode(callSuper = false) | ||
public final class WithListElement extends AstNode { | ||
// TODO: Add support for the search/cycle clause. | ||
|
||
@NotNull | ||
private final Identifier.Simple queryName; | ||
|
||
@NotNull | ||
private final ExprQuerySet asQuery; | ||
|
||
@Nullable | ||
private final List<Identifier.Simple> withColumnList; | ||
|
||
/** | ||
* Creates a new instance of {@link WithListElement}. | ||
* @param queryName the name to bind | ||
* @param asQuery the query that defines the with list element | ||
* @param columnList the list of column names to be output from the query | ||
*/ | ||
public WithListElement(@NotNull Identifier.Simple queryName, @NotNull ExprQuerySet asQuery, @Nullable List<Identifier.Simple> columnList) { | ||
this.queryName = queryName; | ||
this.asQuery = asQuery; | ||
this.withColumnList = columnList; | ||
} | ||
|
||
/** | ||
* Creates a new instance of {@link WithListElement}. | ||
* @param queryName the name to bind | ||
* @param asQuery the query that defines the with list element | ||
*/ | ||
public WithListElement(@NotNull Identifier.Simple queryName, @NotNull ExprQuerySet asQuery) { | ||
this(queryName, asQuery, null); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public List<AstNode> getChildren() { | ||
List<AstNode> children = new ArrayList<>(); | ||
children.add(queryName); | ||
if (withColumnList != null) { | ||
children.addAll(withColumnList); | ||
} | ||
children.add(asQuery); | ||
return children; | ||
} | ||
|
||
@Override | ||
public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) { | ||
return visitor.visitWithListElement(this, ctx); | ||
} | ||
|
||
/** | ||
* Returns the query name. | ||
* @return the query name | ||
*/ | ||
@NotNull | ||
public Identifier.Simple getQueryName() { | ||
return this.queryName; | ||
} | ||
|
||
/** | ||
* Returns the list of column names to be output from the query. | ||
* @return the list of column names to be output from the query. This may return null. | ||
*/ | ||
@Nullable | ||
public List<Identifier.Simple> getColumnList() { | ||
return this.withColumnList; | ||
} | ||
|
||
/** | ||
* Returns the query that defines the with list element. | ||
* @return the query that defines the with list element | ||
*/ | ||
@NotNull | ||
public ExprQuerySet getAsQuery() { | ||
return this.asQuery; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be a helper constructor for
With
inorg.partiql.ast.Ast
?