-
Notifications
You must be signed in to change notification settings - Fork 25k
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
ESQL: Fix layout when aggregating with aliases #117832
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 |
---|---|---|
|
@@ -120,10 +120,14 @@ public final PhysicalOperation groupingPhysicalOperation( | |
* - before stats (keep x = a | stats by x) which requires the partial input to use a's channel | ||
* - after stats (stats by a | keep x = a) which causes the output layout to refer to the follow-up alias | ||
*/ | ||
// TODO: This is likely required only for pre-8.14 node compatibility; confirm and remove if possible. | ||
// Since https://github.com/elastic/elasticsearch/pull/104958, it shouldn't be possible to have aliases in the aggregates | ||
// which the groupings refer to. Except for `BY CATEGORIZE(field)`, which remains as alias in the grouping, all aliases | ||
// should've become EVALs before or after the STATS. | ||
for (NamedExpression agg : aggregates) { | ||
if (agg instanceof Alias a) { | ||
if (a.child() instanceof Attribute attr) { | ||
if (groupAttribute.id().equals(attr.id())) { | ||
if (sourceGroupAttribute.id().equals(attr.id())) { | ||
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.
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 line I just updated for alignment with the rest. It's the change below that actually fixes things. |
||
groupAttributeLayout.nameIds().add(a.id()); | ||
// TODO: investigate whether a break could be used since it shouldn't be possible to have multiple | ||
// attributes pointing to the same attribute | ||
|
@@ -133,8 +137,8 @@ public final PhysicalOperation groupingPhysicalOperation( | |
// is in the output form | ||
// if the group points to an alias declared in the aggregate, use the alias child as source | ||
else if (aggregatorMode.isOutputPartial()) { | ||
if (groupAttribute.semanticEquals(a.toAttribute())) { | ||
groupAttribute = attr; | ||
if (sourceGroupAttribute.semanticEquals(a.toAttribute())) { | ||
sourceGroupAttribute = attr; | ||
break; | ||
Comment on lines
-136
to
142
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. 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.
Should this be merged to main and then backported? To avoid conflicts, and ensure we support "everything everywhere".
I see you commented to fix it here, and then remove the obsolete path in main. But I wonder if it could cause issues in the future. Also, if it fails in <8.13, shouldn't 9.x also support it? Or is 8.13 the last compatible 8.x version?
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.
Nevermind, I see the other PR is identical