[9.1] ESQL: Prevent circular alias references in DeduplicateAggs (#139175)#139617
[9.1] ESQL: Prevent circular alias references in DeduplicateAggs (#139175)#139617elasticsearchmachine merged 10 commits intoelastic:9.1from
DeduplicateAggs (#139175)#139617Conversation
…#139175) ## Summary Fixes circular reference detection in alias chains during `DeduplicateAggs` optimizations. ## Problem The `PushDownEnrich` optimization can create circular references when pushing `Enrich` past `Project` operations, causing `ql_illegal_argument_exception: Potential cycle detected` errors when `DeduplicateAggs`. Example query: ```esql FROM languages_lookup | RENAME language_name AS message | ENRICH languages_policy ON language_code | STATS a = count(to_lower(language_name)), b = count(language_name) ``` ## Changes Skip aliases that would create circular references by checking if `alias.toAttribute()` equals the resolved `alias.child()`. Closes elastic#138346 Closes elastic#139541 (cherry picked from commit 2289e17) # Conflicts: # x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/generative/GenerativeRestTest.java # x-pack/plugin/esql/qa/testFixtures/src/main/resources/enrich.csv-spec # 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
|
@bpintea I had a few hiccups during the backport, but hopefully we’re good now. |
|
buildkite test this |
|
I’ve verified that the query below reproduces the issue on this patch if the code in But something strange happened: in the multi-cluster tests, the response is |
|
Hi @bpintea, Does this CI failure look familiar to you? I was wondering if you might have some insight. |
|
Hey @kanoshiou,
Unfortunately not. :) |
# Conflicts: # x-pack/plugin/esql/qa/testFixtures/src/main/resources/enrich.csv-spec # 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
|
@elasticsearchmachine test this please |
|
@elasticsearchmachine test this please |
This reverts commit b0696b5. Turns out, we cannot use the languages index because this one is also used for enrich, and the multi cluster tests index this two times, on the remote AND on the local cluster.
This happens because the multi-cluster tests (randomly?) turn a Except that the spec test has to work for both multi- and single-cluster tests :) I'll add a copy of the |
|
Thank you for your detailed explanation, @alex-spies! I'm just a bit puzzled by the inconsistent test behavior between branches. |
|
@elasticsearchmachine test this please |
9.1 didn't have lookup joins in CCS, so CCS-tests just didn't allow lookup indices. That's why you didn't see this fail on 9.2, for instance. |
|
@elasticsearchmachine test this please |
|
@elasticsearchmachine test this please |
Backport
This will backport the following commits from
mainto9.1:DeduplicateAggs(#139175)Questions ?
Please refer to the Backport tool documentation