-
Notifications
You must be signed in to change notification settings - Fork 25.2k
ESQL: Have CombineProjections propagate references upwards #127264
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 all commits
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 |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
import org.elasticsearch.xpack.esql.core.expression.Expression; | ||
import org.elasticsearch.xpack.esql.core.expression.Expressions; | ||
import org.elasticsearch.xpack.esql.core.expression.NamedExpression; | ||
import org.elasticsearch.xpack.esql.core.expression.ReferenceAttribute; | ||
import org.elasticsearch.xpack.esql.expression.function.grouping.GroupingFunction; | ||
import org.elasticsearch.xpack.esql.plan.logical.Aggregate; | ||
import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan; | ||
|
@@ -126,6 +127,8 @@ private static List<NamedExpression> combineProjections(List<? extends NamedExpr | |
if (ne instanceof Alias as) { | ||
Expression child = as.child(); | ||
namedExpressionsBuilder.put(ne.toAttribute(), as.replaceChild(aliasesBuilder.build().resolve(child, child))); | ||
} else if (ne instanceof ReferenceAttribute ra) { | ||
namedExpressionsBuilder.put(ra, ra); | ||
Comment on lines
+130
to
+131
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. This captures aliases but now also References - why do we care about them and what about other types of named expression (e.g. FieldAttribute)? 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. My understanding is that this change doesn't affect queries and their computation, it just opportunistically replaces e.g.
but I don't think this makes a difference, really, as the attribute type mismatch between 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.
It's not just then. There'll always be two projections to combine in case of a locally missing field, due to the effects of
IMO the change the PR proposes is a correction, not just "cosmetic". But it's true that it currently makes no practical difference.
I hope the above clarifies. But happy to give further details, if needed. But I'm also happy to revert the change and add a comment instead. :) 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.
It's true that replacing the field attribute by a ref attr downstream in the plan will make But |
||
} | ||
} | ||
List<NamedExpression> replaced = new ArrayList<>(upper.size()); | ||
|
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.
this is an optimization, unrelated to this PR, right?
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.
Correct. It's supposed to avoid creating objects while planning, if not needed. The change is small and not sure if a stand-alone PR would make sense, but happy to revert and split, if needed.