ESQL: Fix multi-value constant propagation after STATS#139442
Merged
ncordon merged 10 commits intoelastic:mainfrom Dec 29, 2025
Merged
ESQL: Fix multi-value constant propagation after STATS#139442ncordon merged 10 commits intoelastic:mainfrom
STATS#139442ncordon merged 10 commits intoelastic:mainfrom
Conversation
…-stats # Conflicts: # x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java # x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/LogicalPlanOptimizerTests.java
# Conflicts: # x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/LogicalPlanOptimizerTests.java
Collaborator
|
Pinging @elastic/es-analytical-engine (Team:Analytics) |
Contributor
|
buildkite test this please |
ncordon
approved these changes
Dec 23, 2025
Contributor
There was a problem hiding this comment.
This looks good to me provided it passes the CI. Thanks a lot for the contribution @kanoshiou!
Contributor
|
buildkite test this please |
Contributor
|
buildkite test this please |
Contributor
Author
|
Thank you for your review, @ncordon! I believe these two CI failures are not related to this PR. I’ve also added the two tests(25a49ab) requested in another PR(#139175 (comment)). Hey @bpintea — I’m not sure if these tests fully match what you had in mind; if not, I’m happy to adjust them. |
mouhc1ne
approved these changes
Dec 24, 2025
Contributor
|
buildkite test this please |
1 similar comment
Contributor
|
buildkite test this please |
Contributor
|
buildkite test this please |
Contributor
Author
Contributor
|
Thanks for your amazing contributions @kanoshiou! I'll backport this to relevant branches. |
rjernst
pushed a commit
to rjernst/elasticsearch
that referenced
this pull request
Dec 29, 2025
Kubik42
pushed a commit
to Kubik42/elasticsearch
that referenced
this pull request
Dec 30, 2025
ncordon
pushed a commit
to ncordon/elasticsearch
that referenced
this pull request
Dec 30, 2025
ncordon
added a commit
to ncordon/elasticsearch
that referenced
this pull request
Dec 30, 2025
ncordon
pushed a commit
to ncordon/elasticsearch
that referenced
this pull request
Dec 30, 2025
ncordon
pushed a commit
to ncordon/elasticsearch
that referenced
this pull request
Dec 30, 2025
ncordon
pushed a commit
to ncordon/elasticsearch
that referenced
this pull request
Dec 30, 2025
ncordon
pushed a commit
to ncordon/elasticsearch
that referenced
this pull request
Dec 30, 2025
ncordon
added a commit
to ncordon/elasticsearch
that referenced
this pull request
Dec 30, 2025
ncordon
pushed a commit
to ncordon/elasticsearch
that referenced
this pull request
Dec 30, 2025
ncordon
added a commit
to ncordon/elasticsearch
that referenced
this pull request
Dec 30, 2025
ncordon
pushed a commit
to ncordon/elasticsearch
that referenced
this pull request
Jan 2, 2026
ncordon
added a commit
to ncordon/elasticsearch
that referenced
this pull request
Jan 2, 2026
elasticsearchmachine
pushed a commit
that referenced
this pull request
Jan 2, 2026
elasticsearchmachine
pushed a commit
that referenced
this pull request
Jan 2, 2026
elasticsearchmachine
pushed a commit
that referenced
this pull request
Jan 2, 2026
elasticsearchmachine
pushed a commit
that referenced
this pull request
Jan 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes an issue where multi-value constants used as
GROUP BYkeys are incorrectly propagated after the aggregation.Problem
When a multi-value constant (e.g.,
[1, 2]) is used as a GROUP BY key, the STATS command explodes it into single values. However, thePropagateEvalFoldablesoptimization rule was propagating the original multi-value literal into expressions after theAggregatenode, which incorrectly treated the field as still being multi-valued.For example, in the query:
Before the fix, a in the
WHEREclause would be incorrectly replaced with the literal[1, 2]instead of the single-value result fromGROUP BY.Solution
Exclude multi-value (List) literals used as
GROUP BYkeys from constant propagation. This ensures that after aggregation, references to grouping keys correctly reflect their single-value nature.Closes #135926