-
Notifications
You must be signed in to change notification settings - Fork 25.6k
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 6 commits
22de40b
8c7df30
8a7fc3d
4f7ff09
1ef4f3a
0b1e2fb
cfe086e
2715306
ed7a3b8
5167d88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,9 +7,14 @@ | |
| package org.elasticsearch.xpack.esql.optimizer.rules.logical; | ||
|
|
||
| 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.Drop; | ||
| import org.elasticsearch.xpack.esql.plan.logical.EsRelation; | ||
| import org.elasticsearch.xpack.esql.plan.logical.Limit; | ||
| 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 +60,27 @@ 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); | ||
|
|
||
| /** | ||
| * Defines if a node should be visited or not. | ||
| * Allows to skip nodes that are not applicable for the rule even if they contain expressions. | ||
| * By default that skips FROM, LIMIT, PROJECT, KEEP and DROP but this list could be extended or replaced in subclasses. | ||
|
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. How did you come up with this list of commands/node types? 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. Those are commands that are either common but have not expressions (limit) or common, contain list of attributes but do not require any optimization or rearranging (such as keep/project/drop) if properly constructed they only contain plain list of attribute used. 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. For more context: @idegtiarenko found out that the simple |
||
| */ | ||
| protected boolean shouldVisit(Node<?> node) { | ||
| return switch (node) { | ||
| case EsRelation relation -> false; | ||
| case Project project -> false;// this covers both keep and project | ||
| case Drop drop -> false; | ||
alex-spies marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| case Limit limit -> false; | ||
| 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.
Isn't there a physical plan equivalent?
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.
Yes,
org.elasticsearch.xpack.esql.optimizer.PhysicalOptimizerRules, however it does not seem to have an rules forexpressions.