Skip to content

ESQL: Skip nullifying aliases for Aggregate groups#141340

Merged
alex-spies merged 41 commits intoelastic:mainfrom
bpintea:fix/unmapped_no_grouping_aliases
Mar 10, 2026
Merged

ESQL: Skip nullifying aliases for Aggregate groups#141340
alex-spies merged 41 commits intoelastic:mainfrom
bpintea:fix/unmapped_no_grouping_aliases

Conversation

@bpintea
Copy link
Copy Markdown
Contributor

@bpintea bpintea commented Jan 27, 2026

This re-introduces skipping the UnresolvedAttributes that are
collected from the Aggregate#aggregates and are Aliases in the
#groupings. In this case, the aliases, not their child, result in an
UnresolvedAttribute. This must not be nullified, since they'll be
subsequently resolved part of Alias'es child resolution.

The side effect of doing otherwise is that they can shadow attributes
produced by the source or Eval'd.

Related, in Aggregate resoluion skip resolving the aggregates based on
those input attributes that share a name with the not-yet-resolved
UnresolvedAttributes. This was incorrect, but didn't occur before
unmapped-fields fieature since the resolution of the Aggregate all
happened in one Analyzer cycle (unlike with unmapped-fields).

Another fix concerns skipping the right-hand side of Joins when
introducing null-aliases.
Also, null-aliases are no longer introduced behind Aggregates
if these shadow an existing source. (This is a moot change, since in
this case the plan verification would fail anyways. But it is the correct
way.)

bpintea and others added 7 commits January 26, 2026 12:11
This fixes the generation of name IDs for the attributes corresponding
to the unmapped fields and are pushed to different branches in UntionAll.

So far, one set of IDs was generated and reused for all subplans. This
is now updated to own set per subplan.

A minor collateral proposed change: the CSV spec-based tests skipped due
to missing capabilities are now logged.
This re-introduces skipping the `UnresolvedAttribute`s that are
collected from the `Aggregate#aggregates` and are `Alias`es in the
`#groupings`. In this case, the aliases, not their child, result in an
`UnresolvedAttribute`. This must not be nullified, since they'll be
subsequently resolved part of `Alias`'es child resolution.

The side effect of doing otherwise is that they can shadow attributes
produced by the source or `Eval`'d.

Related, in Aggregate resoluion skip resolving the aggregates based on
those input attributes that share a name with the not-yet-resolved
`UnresolvedAttribute`s. This was incorrect, but didn't occur before
unmapped-fields fieature since the resolution of the `Aggregate` all
happened in one Analyzer cycle (unlike with unmapped-fields).
- LookupJoin no longer has Evals inserted on the right-hand side
- nullifying now only iterates the plan once
- make use of the new transformDownSkipBranch
- avoid shadowing source attributes behind Aggregates
- check resuling plan on statement analysis
@bpintea bpintea added auto-backport Automatically create backport pull requests when merged and removed WIP labels Jan 30, 2026
@bpintea bpintea requested review from GalLalouche, alex-spies and astefan and removed request for GalLalouche January 30, 2026 06:09
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Hi @bpintea, I've created a changelog YAML for you.

@bpintea bpintea marked this pull request as ready for review January 30, 2026 06:10
@elasticsearchmachine elasticsearchmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Jan 30, 2026
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-analytical-engine (Team:Analytics)

@alex-spies
Copy link
Copy Markdown
Contributor

Ok, all comments addressed. I'll merge + backport this now.

@alex-spies alex-spies merged commit f7b87e3 into elastic:main Mar 10, 2026
36 checks passed
@elasticsearchmachine
Copy link
Copy Markdown
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 141340

@alex-spies
Copy link
Copy Markdown
Contributor

💚 All backports created successfully

Status Branch Result
9.3

Questions ?

Please refer to the Backport tool documentation

alex-spies pushed a commit to alex-spies/elasticsearch that referenced this pull request Mar 12, 2026
* Fix injected attributes's IDs on UnionAll branches
* Skip nullifying of aliases for Aggregate groups
* Fix LookupJoin getting Evals inserted on the right-hand side
* Log skipped spec tests if capabilities were missing
* Add minimal TS spec tests for nullify
* Add reproducer test for join issue
* Add spec test: STATS BY missing with FROM

---------

Co-authored-by: Alexander Spies <alexander.spies@elastic.co>
Co-authored-by: Ievgen Degtiarenko <ievgen.degtiarenko@elastic.co>
Co-authored-by: elasticsearchmachine <infra-root+elasticsearchmachine@elastic.co>
(cherry picked from commit f7b87e3)

# Conflicts:
#	muted-tests.yml
#	x-pack/plugin/esql/qa/testFixtures/src/main/resources/unmapped-nullify.csv-spec
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/Analyzer.java
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/rules/ResolveUnmapped.java
#	x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/AnalyzerUnmappedTests.java
elasticsearchmachine pushed a commit that referenced this pull request Mar 13, 2026
…144097)

* ESQL: Skip nullifying aliases for Aggregate groups (#141340)

* Fix injected attributes's IDs on UnionAll branches
* Skip nullifying of aliases for Aggregate groups
* Fix LookupJoin getting Evals inserted on the right-hand side
* Log skipped spec tests if capabilities were missing
* Add minimal TS spec tests for nullify
* Add reproducer test for join issue
* Add spec test: STATS BY missing with FROM

---------

Co-authored-by: Alexander Spies <alexander.spies@elastic.co>
Co-authored-by: Ievgen Degtiarenko <ievgen.degtiarenko@elastic.co>
Co-authored-by: elasticsearchmachine <infra-root+elasticsearchmachine@elastic.co>
(cherry picked from commit f7b87e3)

# Conflicts:
#	muted-tests.yml
#	x-pack/plugin/esql/qa/testFixtures/src/main/resources/unmapped-nullify.csv-spec
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/Analyzer.java
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/rules/ResolveUnmapped.java
#	x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/AnalyzerUnmappedTests.java

* [CI] Auto commit changes from spotless

* Remove accidentally committed spec tests

* Fix some more conflict mis-resolutions

* Add transformDownSkipBranch

* Make tests run the same in multi cluster suite

* Remove redundant test

tsImplicitTimestampSortBasicWithMissing cannot run on 9.3 because it
requires the ts_implicit_timestamp_sort capability.

---------

Co-authored-by: Bogdan Pintea <bogdan.pintea@elastic.co>
Co-authored-by: elasticsearchmachine <infra-root+elasticsearchmachine@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Analytics/ES|QL AKA ESQL auto-backport Automatically create backport pull requests when merged backport pending >bug Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v9.3.2 v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants