-
Notifications
You must be signed in to change notification settings - Fork 26k
ESQL: Fix variable shadowing when pushing down past Project #108360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 20 commits
2554ee1
16dc1ff
c6396fc
79a2f2d
2979314
96c55b3
f21e47b
717f9cd
7a74e46
c456b2f
06cd647
dbe12b6
dce915f
c9b94e8
c061b64
b93f481
3684d13
dd6abad
2ac1257
ac31ef4
b87ae72
fc5fec5
c8dd4a6
7f3f7b9
28c2606
28477a9
b1c0d7b
8fc9c03
d939a4d
23769d2
efbc2dd
c80ddf4
1fa5462
4e8f828
17cfbc8
f904f54
33e8ac4
edd2f7f
32c5fba
73ba36c
db3304d
984bd98
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -663,6 +663,61 @@ ca:l | cx:l | l:i | |
| 1 | 1 | null | ||
| ; | ||
|
|
||
| /////////////////////////////////////////////////////////////// | ||
| // Test edge case interaction with push down optimization rules | ||
| // https://github.com/elastic/elasticsearch/issues/108008 | ||
| /////////////////////////////////////////////////////////////// | ||
|
|
||
| // TODO: we update capabilities | ||
| countSameFieldWithEval | ||
| from employees | stats b = count(gender), c = count(gender) by gender | eval b = gender | sort c asc | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand the goal is to make the query run to completion, but the first time I looked at this query, the alias b looks ambiguous, should it be gender or count(gender)? Seems like we return b as gender, it overwrites count(gender), but when pushdown happens, the order might be reversed. In SQL, if users code ambiguous column references, an error will return. Should we return an error here to indicate that b is ambiguous or make it return successfully here(if we have agreement in ES|QL that if the same alias is defined in multiple places, the last one will take effect)?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we should throw errors. Masking happens all the time, even a simple
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @fang-xing-esql - ESQL in general allows shadowing attribute names that have been available previously. Take a look at the The main idea is that we want to be able to compose expressions in eval, like |
||
| ; | ||
|
|
||
| c:l | gender:s | b:s | ||
| 0 | null | null | ||
| 33 | F | F | ||
|
alex-spies marked this conversation as resolved.
|
||
| 57 | M | M | ||
| ; | ||
|
|
||
| countSameFieldWithDissect | ||
| from employees | stats b = count(gender), c = count(gender) by gender | dissect gender "%{b}" | sort c asc | ||
| ; | ||
|
|
||
| c:l | gender:s | b:s | ||
| 0 | null | null | ||
| 33 | F | F | ||
| 57 | M | M | ||
| ; | ||
|
|
||
| countSameFieldWithGrok | ||
| from employees | stats b = count(gender), c = count(gender) by gender | grok gender "%{USERNAME:b}" | sort c asc | ||
| ; | ||
|
|
||
| c:l | gender:s | b:s | ||
| 0 | null | null | ||
| 33 | F | F | ||
| 57 | M | M | ||
| ; | ||
|
|
||
| countSameFieldWithEnrich | ||
| required_capability: enrich_load | ||
| from employees | stats b = count(gender), c = count(gender) by gender | enrich languages_policy on gender with b = language_name | sort c asc | ||
| ; | ||
|
|
||
| c:l | gender:s | b:s | ||
| 0 | null | null | ||
| 33 | F | null | ||
| 57 | M | null | ||
| ; | ||
|
|
||
| countSameFieldWithEnrichLimit0 | ||
| from employees | stats b = count(gender), c = count(gender) by gender | enrich languages_policy on gender with b = language_name | sort c asc | limit 0 | ||
| ; | ||
|
|
||
| c:l | gender:s | b:s | ||
| ; | ||
| /////////////////////////////////////////////////////////////// | ||
|
|
||
| aggsWithoutStats | ||
| from employees | stats by gender | sort gender; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.esql.plan; | ||
|
|
||
| import org.elasticsearch.xpack.esql.core.expression.Attribute; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public interface GeneratingPlan<PlanType extends GeneratingPlan<PlanType>> { | ||
|
alex-spies marked this conversation as resolved.
|
||
| List<Attribute> generatedAttributes(); | ||
|
|
||
| PlanType withGeneratedNames(List<String> newNames); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd really love to have a couple more tests here, where you have multiple expressions in the same EVAL (and GROK, DISSECT...), where some are masked and some are not.
Also, some tests where the EVAL uses masked names in following expressions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I increased unit test coverage (multiple expressions in the same EVAL) and will add a couple more csv tests where we sometimes shadow, sometimes not.
I'll avoid adding them to
stats.csv-spec, though, and will not includeSTATScommands in the tests; the fact thatSTATStriggered this bug is merely accidentaly, it's reallyRENAME ... | EVAL ...and similar that lead to this problem.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added.