-
Notifications
You must be signed in to change notification settings - Fork 25.3k
Make OptimizerExpressionRule conditional #127500
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
Changes from 1 commit
22de40b
8c7df30
8a7fc3d
4f7ff09
1ef4f3a
0b1e2fb
cfe086e
2715306
ed7a3b8
5167d88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,9 +7,12 @@ | |
package org.elasticsearch.xpack.esql.optimizer.rules.logical; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't there a physical plan equivalent? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, |
||
|
||
import org.elasticsearch.xpack.esql.core.expression.Expression; | ||
import org.elasticsearch.xpack.esql.core.tree.Node; | ||
import org.elasticsearch.xpack.esql.core.util.ReflectionUtils; | ||
import org.elasticsearch.xpack.esql.optimizer.LogicalOptimizerContext; | ||
import org.elasticsearch.xpack.esql.plan.logical.EsRelation; | ||
import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan; | ||
import org.elasticsearch.xpack.esql.plan.logical.Project; | ||
import org.elasticsearch.xpack.esql.rule.ParameterizedRule; | ||
import org.elasticsearch.xpack.esql.rule.Rule; | ||
|
||
|
@@ -55,12 +58,20 @@ public OptimizerExpressionRule(TransformDirection direction) { | |
@Override | ||
public final LogicalPlan apply(LogicalPlan plan, LogicalOptimizerContext ctx) { | ||
return direction == TransformDirection.DOWN | ||
? plan.transformExpressionsDown(expressionTypeToken, e -> rule(e, ctx)) | ||
: plan.transformExpressionsUp(expressionTypeToken, e -> rule(e, ctx)); | ||
? plan.transformExpressionsDown(this::shouldVisit, expressionTypeToken, e -> rule(e, ctx)) | ||
: plan.transformExpressionsUp(this::shouldVisit, expressionTypeToken, e -> rule(e, ctx)); | ||
} | ||
|
||
protected abstract Expression rule(E e, LogicalOptimizerContext ctx); | ||
|
||
protected boolean shouldVisit(Node<?> node) { | ||
return switch (node) { | ||
case EsRelation esr -> false; | ||
case Project p -> false;// this covers both keep and project | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: IMO we should document in the javadoc that relation + projection are getting skipped per default and that one should override There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair point. I opened a draft at this point to see if this breaks a lot of tests (it did not 🎉 ) so now I will focus no documenting and testing it. |
||
default -> true; | ||
}; | ||
} | ||
|
||
public Class<E> expressionToken() { | ||
return expressionTypeToken; | ||
} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why remove the previous methods? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They are unused at the moment. Please let me know if we should keep them anyways |
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.
nit:
we don't have class tokens here.