Skip to content

Commit b808bba

Browse files
committed
Retain aggregates
1 parent 591fa87 commit b808bba

File tree

1 file changed

+4
-1
lines changed
  • x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/rules/logical

1 file changed

+4
-1
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/rules/logical/PruneColumns.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import org.elasticsearch.compute.data.Block;
1111
import org.elasticsearch.compute.data.BlockUtils;
1212
import org.elasticsearch.index.IndexMode;
13+
import org.elasticsearch.xpack.esql.core.expression.Alias;
14+
import org.elasticsearch.xpack.esql.core.expression.Attribute;
1315
import org.elasticsearch.xpack.esql.core.expression.AttributeSet;
1416
import org.elasticsearch.xpack.esql.core.expression.EmptyAttribute;
1517
import org.elasticsearch.xpack.esql.core.expression.Expressions;
@@ -84,7 +86,8 @@ public LogicalPlan apply(LogicalPlan plan) {
8486
);
8587
} else {
8688
// Aggs cannot produce pages with 0 columns, so retain one grouping.
87-
remaining = List.of(Expressions.attribute(aggregate.groupings().get(0)));
89+
Attribute attribute = Expressions.attribute(aggregate.groupings().getFirst());
90+
remaining = aggregate.aggregates().stream().map(v -> new Alias(v.source(), v.name(), attribute)).toList();
8891
p = aggregate.with(aggregate.groupings(), remaining);
8992
}
9093
} else {

0 commit comments

Comments
 (0)