-
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 basic strategies to compiler (see #1625) #1644
Conversation
/** | ||
* Get the i-th operator (pre-order) matched by the pattern. | ||
* | ||
* @param i 0-indexed | ||
* @return Operator | ||
*/ | ||
@NotNull | ||
public Operator operator(int i) { | ||
return operators[i]; | ||
} | ||
|
||
/** | ||
* Get the i-th input to this pattern. | ||
* | ||
* @param i 0-indexed | ||
* @return Expr | ||
*/ | ||
@NotNull | ||
public List<Expr> children(int i) { | ||
return children.get(i); | ||
} |
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: naming?
@NotNull | ||
private final Pattern pattern; |
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: since this is an abstract class, it might be worth making the field public and removing the getter.
if (strategy.getPattern().matches(operator)) { | ||
// compile children | ||
val children = operator.getChildren().map { compileWithStrategies(it, ctx) } | ||
val match = Match(operator, children) | ||
return strategy.apply(match) | ||
} |
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: this shows how we can recurse to compile the children, then include those in the match object.
/** | ||
* Get i-th child (input) operator. | ||
* | ||
* @param index | ||
*/ | ||
public fun getChild(index: Int) { | ||
throw UnsupportedOperationException("getChild") | ||
} |
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: get i-th child is crucial to building the match structures but is unused now.
/** | ||
* @return a PartiQL row type | ||
* @deprecated this API is experimental and is subject to modification/deletion without prior notice. | ||
*/ | ||
@NotNull | ||
static PType row(@NotNull Field... fields) { | ||
return new PTypeRow(Arrays.asList(fields)); | ||
} | ||
|
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: auto-formatting messed with some things. All I've done is added the row
helper.
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-0A305C4). 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
|
import java.util.List; | ||
|
||
/** | ||
* Match represents a subtree match to be sent to the |
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.
* Match represents a subtree match to be sent to the | |
* Match represents a subtree match to be sent to a strategy. |
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.
LGTM
val input = "select * from [1,2] limit 100" | ||
compile(input, strategy) | ||
// assert the strategy was triggered | ||
assertTrue(trigged, "the compiler did not apply the custom strategy") |
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.
Non-blocking nit.
assertTrue(trigged, "the compiler did not apply the custom strategy") | |
assertTrue(trigged, "the compiler applied the custom strategy") |
Relevant Issues
#1625
Description
This PR defines a single node pattern along with the strategy API. This allows you to define a "strategy" or hook to insert custom implementations of certain nodes.
Other Information
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.