Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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())) {
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
Expand All @@ -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;
}
}
Expand Down