-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
ESQL: Remove aliasing inside Eval #100238
Conversation
Pinging @elastic/es-ql (Team:QL) |
Pinging @elastic/elasticsearch-esql (:Query Languages/ES|QL) |
defb7bd
to
5ec7954
Compare
* \_FieldExtractExec[salary{f}#20] | ||
* \_EsQueryExec[test], query[{"esql_single_value":{"field":"emp_no","next":{"range":{"emp_no":{"lt":10050,"boost":1.0}}}}}] | ||
* [_doc{f}#42], limit[], sort[] estimatedRowSize[16] | ||
* \_EsStatsQueryExec[test], stats[Stat[name=salary, type=COUNT, query={ |
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.
This is a great example on how this PR helps - since the eval goes away, there's no field extraction needed.
Depending on the test runs, I'd like to get this PR in 8.11 since several queries with aggs end up simplified (see the extra tests). |
Limiter.ONCE, | ||
new SubstituteSurrogates(), | ||
new ReplaceRegexMatch(), | ||
new ReplaceAliasingEvalWithProject() |
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.
The nice thing about the current state of the rule is that it only gets applied once.
assertThat(aggregate.aggregates(), hasSize(1)); | ||
var alias = as(aggregate.aggregates().get(0), Alias.class); | ||
var count = as(alias.child(), Count.class); | ||
var eval = as(aggregate.child(), Eval.class); | ||
assertThat(eval.fields(), hasSize(1)); | ||
var field = as(eval.fields().get(0), Alias.class); | ||
assertThat(field.name(), is("x")); | ||
var source = as(eval.child(), EsRelation.class); |
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.
Note how the intermediate evals were removed.
var project = as(plan, Project.class); | ||
var eval = as(project.child(), Eval.class); | ||
var limit = as(eval.child(), Limit.class); |
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.
Same here
Evals that introduce aliased can be simplified by extracting them into a project (and thus signaling there's no underlying processing). The following eval: eval x = a + 1, y = x, z = y + 1, y = z, w = y + 1 can be converted into: eval x = a + 1, z = a + 1 + 1, w = a + 1 + 1 | project x, z, z as y, w Fix elastic#100174
5ec7954
to
c7ccdfc
Compare
Your description is slightly wrong:
it should be (notice
|
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.
LGTM, especially the simplifications (and performance improvements) it's adding to queries where evaluation of expressions is not performed when not actually needed.
I have concerns regarding the Layout check that has been commented, combined with the bug I referenced. I am not sure anymore why the check has been added in the first place. I've seen this check being commented in the past as well. Is there an issue waiting to be fixed/implemented for this check to stay as is?
x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/planner/Layout.java
Show resolved
Hide resolved
...k/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/LogicalPlanOptimizer.java
Show resolved
Hide resolved
247fb29
to
c4457d9
Compare
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.
LGTM
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.
Nice.
if (prev != null) { | ||
throw new IllegalArgumentException("Name [" + id + "] is on two channels [" + prev + "] and [" + next + "]"); | ||
} | ||
// Do allow multiple name to point to the same channel - see https://github.com/elastic/elasticsearch/pull/100238 |
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.
// Do allow multiple name to point to the same channel - see https://github.com/elastic/elasticsearch/pull/100238 | |
// Do allow multiple name to point to the same channel - see https://github.com/elastic/elasticsearch/pull/100299 |
Hi @costin, I've created a changelog YAML for you. |
💚 Backport successful
|
Evals that introduce aliased can be simplified by extracting them into a project (and thus signaling there's no underlying processing). The following eval: eval x = a + 1, y = x, z = y + 1, y = z, w = y + 1 can be converted into: eval x = a + 1, z = a + 1 + 1, w = a + 1 + 1 | project x, z, z as y, w Fix elastic#100174 Fix elastic#100050
I think this started failing #100356 |
* ESQL: Remove aliasing inside Eval (#100238) Evals that introduce aliased can be simplified by extracting them into a project (and thus signaling there's no underlying processing). The following eval: eval x = a + 1, y = x, z = y + 1, y = z, w = y + 1 can be converted into: eval x = a + 1, z = a + 1 + 1, w = a + 1 + 1 | project x, z, z as y, w Fix #100174 Fix #100050 * Incorporate #100357 * Temporarily disable failing test Relates #100365 (cherry picked from commit 0ef4da2) * ESQL: Temporarily disable huge concat tests (#100352) We're working on these and we have a plan! (cherry picked from commit acca114) --------- Co-authored-by: Nik Everett <[email protected]>
Evals that introduce aliased can be simplified by extracting them into a
project (and thus signaling there's no underlying processing).
The following eval:
eval x = a + 1, y = x, z = y + 1, y = z, w = y + 1
can be converted into:
eval x = a + 1, z = a + 1 + 1, w = a + 1 + 1 + 1 | project x, z, z as y, w
Fix #100174