Skip to content

[ES|QL] Fix TS bug when grouping on aliases#141568

Merged
limotova merged 9 commits intoelastic:mainfrom
limotova:grouping-on-alias
Feb 4, 2026
Merged

[ES|QL] Fix TS bug when grouping on aliases#141568
limotova merged 9 commits intoelastic:mainfrom
limotova:grouping-on-alias

Conversation

@limotova
Copy link
Contributor

In queries like max(max_over_time(field)) by p = pod, we end up
an Alias in our grouping, which causes a failure: "expected named
expression for grouping". This commit fixes that and allows us to
group on aliases, and by extension evals like to_upper(pod) as
well.

In queries like `max(max_over_time(field)) by p = pod`, we end up
an Alias in our grouping, which causes a failure: "expected named
expression for grouping". This commit fixes that and allows us to
group on aliases, and by extension evals like `to_upper(pod)` as
well.
@limotova limotova added >bug :StorageEngine/ES|QL Timeseries / metrics / PromQL / logsdb capabilities in ES|QL labels Jan 30, 2026
@limotova limotova marked this pull request as ready for review January 30, 2026 08:46
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-storage-engine (Team:StorageEngine)

@limotova limotova requested a review from dnhatn January 30, 2026 08:48
@dnhatn dnhatn added v9.3.0 auto-backport Automatically create backport pull requests when merged labels Jan 30, 2026
Copy link
Member

@dnhatn dnhatn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment, but the fix looks great. Can you add a unit test in LogicalPlanOptimizerTests please? Thanks, Larisa!

List<Expression> firstPassGroupings,
List<Expression> secondPassGroupings
) {
firstPassGroupings.add(timeBucket);
Copy link
Member

@dnhatn dnhatn Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to handle cases where timeBucket is a ReferenceAttribute.

@limotova limotova requested a review from dnhatn February 3, 2026 01:24
Copy link
Member

@dnhatn dnhatn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks Larisa!

@limotova limotova self-assigned this Feb 3, 2026
@limotova limotova merged commit 8b07047 into elastic:main Feb 4, 2026
35 checks passed
@limotova limotova deleted the grouping-on-alias branch February 4, 2026 06:46
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
9.3 Commit could not be cherrypicked due to conflicts

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 141568

@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
9.3 Commit could not be cherrypicked due to conflicts

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 141568

jfreden pushed a commit to jfreden/elasticsearch that referenced this pull request Feb 4, 2026
In queries like `max(max_over_time(field)) by p = pod`, we end up
an Alias in our grouping, which causes a failure: "expected named
expression for grouping". This commit fixes that and allows us to
group on aliases, and by extension evals like `to_upper(pod)` as
well.
spinscale pushed a commit to spinscale/elasticsearch that referenced this pull request Feb 4, 2026
In queries like `max(max_over_time(field)) by p = pod`, we end up
an Alias in our grouping, which causes a failure: "expected named
expression for grouping". This commit fixes that and allows us to
group on aliases, and by extension evals like `to_upper(pod)` as
well.
limotova added a commit to limotova/elasticsearch that referenced this pull request Feb 4, 2026
elasticsearchmachine pushed a commit that referenced this pull request Feb 4, 2026
* [9.3] [ES|QL] Fix TS bug when grouping on aliases (#141568)

Manual backport of #141568

* disable logical plan optimizer test

g is a ReferenceAttribute and not a FieldAttribute, which results
in it not being a dimension, and thus we end up with normal
Values instead of DimensionValues
mamazzol pushed a commit to mamazzol/elasticsearch that referenced this pull request Feb 5, 2026
In queries like `max(max_over_time(field)) by p = pod`, we end up
an Alias in our grouping, which causes a failure: "expected named
expression for grouping". This commit fixes that and allows us to
group on aliases, and by extension evals like `to_upper(pod)` as
well.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-backport Automatically create backport pull requests when merged >bug :StorageEngine/ES|QL Timeseries / metrics / PromQL / logsdb capabilities in ES|QL Team:StorageEngine v9.3.0 v9.4.0

3 participants