-
Notifications
You must be signed in to change notification settings - Fork 62
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
[v1] Adds AstVisitor and AstRewriter; port partiql-ast normalization passes to partiql-planner #1629
Conversation
fd6c81a
to
8c863a0
Compare
@@ -6,6 +6,8 @@ import org.partiql.ast.builder.ast | |||
import org.partiql.value.PartiQLValueExperimental | |||
import org.partiql.value.StringValue | |||
|
|||
// TODO DELETE FILE |
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.
These partiql-ast files marked w/ // TODO DELETE FILE
will be deleted once the sprout-generated AST is deleted.
partiql-ast/src/main/java/org/partiql/ast/v1/expr/SessionAttribute.java
Outdated
Show resolved
Hide resolved
CROSS-ENGINE-REPORT ❌
Testing Details
Result Details
Now FAILING Tests ❌The following 3 test(s) were previously PASSING in BASE but are now FAILING in TARGET: Click here to see
Now IGNORED Tests ❌The complete list can be found in GitHub CI summary, either from Step Summary or in the Artifact. Now Passing Tests180 test(s) were previously failing in BASE (LEGACY-V0.14.8) but now pass in TARGET (EVAL-2BE7C0F). Before merging, confirm they are intended to pass. The complete list can be found in GitHub CI summary, either from Step Summary or in the Artifact. CROSS-COMMIT-REPORT ✅
Testing DetailsResult Details
|
7a68858
to
8eae47f
Compare
8c863a0
to
eeae1fd
Compare
8eae47f
to
43584f9
Compare
eeae1fd
to
1154b30
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## v1-migrate-ast-parser #1629 +/- ##
========================================================
Coverage 80.03% 80.03%
Complexity 47 47
========================================================
Files 19 19
Lines 506 506
Branches 23 23
========================================================
Hits 405 405
Misses 88 88
Partials 13 13
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
238ef60
to
055db0d
Compare
43584f9
to
31d6fd0
Compare
055db0d
to
cb9dd8a
Compare
31d6fd0
to
8751c18
Compare
cb9dd8a
to
3688156
Compare
8751c18
to
da868e1
Compare
3688156
to
cf6a2fa
Compare
Going to mark this as a draft till I fix the visitor modeling a bit. |
cf6a2fa
to
23c1a3c
Compare
import org.partiql.ast.v1.graph.GraphSelector | ||
import org.partiql.value.PartiQLValueExperimental | ||
|
||
public abstract class AstRewriter<C> : AstVisitor<AstNode, C> { |
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.
(self-review) AstRewriter
written in Kotlin since it was slightly easier to create based on the sprout-generated AstRewriter
. I believe it should have similar public API as if it was in Java but if not, I can migrate it to Java.
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.
I can check the decompiled bytecode, but this resides in the java
source set btw.
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.
but this resides in the java source set btw.
Yeah, I'll fix this in a later PR (probably the PR that deletes the sprout AST code). There's some other Kotlin sources in the java
directory that I'll also move in that PR.
…asses to partiql-planner
23c1a3c
to
1bb9b21
Compare
R visitGraphLabelConj(GraphLabel.Conj node, C ctx); | ||
|
||
R visitGraphLabelDisj(GraphLabel.Disj node, C ctx); | ||
public abstract class AstVisitor<R, C> { |
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.
For all of these, I'd indicate in the JVM signature and Javadocs that it might throw an IllegalStateException
if the variant is not officially supported. Maybe link to some documentation about how one can successfully add a new variant without blowing up their visitors.
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.
Replacing the instanceOf
checking with the node.accept(...)
calls for the sum type visit methods (from your comment) would get rid of the IllegalStateException
s.
I'll add docs and a usage guide in a subsequent PR once the APIs are more finalized.
if (node instanceof Query) { | ||
return visitQuery((Query) node, ctx); | ||
} else if (node instanceof Explain) { | ||
return visitExplain((Explain) node, ctx); | ||
} else { | ||
throw new IllegalStateException("Unexpected value: " + node); | ||
} |
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.
I'm trying to think about how we can make it easier for users to add their own custom nodes without breaking their visitors completely. Is there something wrong with just:
if (node instanceof Query) { | |
return visitQuery((Query) node, ctx); | |
} else if (node instanceof Explain) { | |
return visitExplain((Explain) node, ctx); | |
} else { | |
throw new IllegalStateException("Unexpected value: " + node); | |
} | |
node.accept(this, ctx) |
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.
Theoretically, each variant of a sum type would look like:
public class Query : AstNode() {
@Override
public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) {
return visitor.visitQuery(this, ctx);
}
}
So, it would definitely work for the built-in variants. For the other variants, I'm not entirely sure how they'd be able to invoke a custom visit (AKA visitor.visitCustomNode(this, ctx)
).
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.
You're right about the simplification. Those sum type visit functions can be simplified to node.accept(this, ctx)
. I will change.
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.
From offline discussion, there's pros/cons to both approaches. There are some drawbacks to the node.accept
default for the sum types, primarily a user of this library would need to be careful with overriding the proper methods when adding their own variants. This can hopefully be resolved by including some good usage guides.
I do like your suggested approach a bit more since it will simplify what we (the PartiQL team) need to add when adding a new variant.
partiql-planner/src/main/kotlin/org/partiql/planner/internal/normalize/Normalize.kt
Show resolved
Hide resolved
import org.partiql.ast.v1.graph.GraphSelector | ||
import org.partiql.value.PartiQLValueExperimental | ||
|
||
public abstract class AstRewriter<C> : AstVisitor<AstNode, C> { |
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.
I can check the decompiled bytecode, but this resides in the java
source set btw.
…passes to partiql-planner (#1629)
Relevant Issues
Description
AstVisitor
an abstract class with defaultsAstRewriter
internal
AstVisitor
impls are to be added in a subsequent PROther Information
Updated Unreleased Section in CHANGELOG: [NO]
Any backward-incompatible changes? [NO]
Any new external dependencies? [NO]
Do your changes comply with the Contributing Guidelines
and Code Style Guidelines? [YES]
License Information
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.