Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/135247.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 135247
summary: Fix alias id when drop all aggregates
area: ES|QL
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -788,3 +788,20 @@ from firewall_logs,threat_list,airports
dsjbDWegyVkg:boolean | name:integer | nhIWDevxEtU:null | iPIbTFddDK:integer | rUvqtgSl:integer
false | 1 | null | 1 | 1
;

evalAfterGroupingUsingSameName6
required_capability: fix_alias_id_when_drop_all_aggregates
from employees
| stats sum=sum(salary) by last_name, year = bucket(birth_date, 1 year)
| DROP sum
| DROP last_name
| eval year = 12
| LIMIT 4
;

year:integer
12
12
12
12
;
Original file line number Diff line number Diff line change
Expand Up @@ -1538,6 +1538,8 @@ public enum Cap {
*/
TS_COMMAND_V0(),

FIX_ALIAS_ID_WHEN_DROP_ALL_AGGREGATES

;

private final boolean enabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private static LogicalPlan pruneColumnsInAggregate(Aggregate aggregate, Attribut
// Aggs cannot produce pages with 0 columns, so retain one grouping.
Attribute attribute = Expressions.attribute(aggregate.groupings().getFirst());
NamedExpression firstAggregate = aggregate.aggregates().getFirst();
remaining = List.of(new Alias(firstAggregate.source(), firstAggregate.name(), attribute, firstAggregate.id()));
remaining = List.of(new Alias(firstAggregate.source(), firstAggregate.name(), attribute, attribute.id()));
p = aggregate.with(aggregate.groupings(), remaining);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ public void testEmptyProjectInStatWithGroupAndEval() {

assertThat(Expressions.names(agg.groupings()), contains("emp_no"));
assertThat(Expressions.names(agg.aggregates()), contains("c"));
assertThat(agg.aggregates().get(0).id(), equalTo(Expressions.attribute(agg.groupings().get(0)).id()));

var exprs = eval.fields();
assertThat(exprs.size(), equalTo(1));
Expand Down