Skip to content

ESQL: Align RENAME behavior with EVAL for sequential processing #122250

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

Merged
merged 14 commits into from
Mar 20, 2025

Conversation

kanoshiou
Copy link
Contributor

@kanoshiou kanoshiou commented Feb 11, 2025

The RENAME command should function as similarly to other commands like EVAL as possible, executing operations sequentially from left to right.

For example, the following query:

row  foo = 10, bar = null | rename bar AS foo, foo AS bar

is equivalent to:

row foo = 10, bar = null 
| rename bar AS foo  // foo = null (`bar` is renamed to `foo`, making the original `foo` inaccessible)
| rename foo AS bar  // bar = null (the new `foo` is then renamed to `bar`)

and should produce the result:

      bar      
---------------
null                  

Closes #121739

@elasticsearchmachine elasticsearchmachine added needs:triage Requires assignment of a team area label v9.1.0 external-contributor Pull request authored by a developer outside the Elasticsearch team labels Feb 11, 2025
@kanoshiou
Copy link
Contributor Author

kanoshiou commented Feb 11, 2025

During code validation, a question arose:

row foo = 10, bar = null | rename bar2 as bar2

When the pre-modification name and the post-modification name are the same, should it throw a VerificationException of unknown column ? Currently, it simply ignores this rename operation.

I think #122165 is a related issue to this problem.

@limotova limotova added :Analytics/ES|QL AKA ESQL and removed needs:triage Requires assignment of a team area label labels Feb 14, 2025
@elasticsearchmachine elasticsearchmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Feb 14, 2025
@elasticsearchmachine
Copy link
Collaborator

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

@ivancea ivancea self-requested a review February 19, 2025 18:01
@kanoshiou kanoshiou changed the title ES|QL: Improve RENAME logic to swap names ESQL: Improve RENAME logic to swap names Feb 21, 2025
@astefan
Copy link
Contributor

astefan commented Feb 26, 2025

@kanoshiou thank you for this contribution. At this point, though, this subject is in internal discussions on how ES|QL should actually behave in this case. There are other similar scenarios in other queries involving overrides and all of these should be considered when making a decision.
This is just an fyi and for setting expectations on our responsiveness for this PR review. Thank you for your understanding.

@astefan astefan requested a review from bpintea March 7, 2025 15:34
Copy link
Contributor

@ivancea ivancea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @kanoshiou, sorry for the delay!
After some discussions, we want to keep RENAME as similar as other commands like EVAL as possible, where operations are "executed" from left to right.

For RENAME, it means that:

| RENAME a AS b, b AS c

Should be identical to:

| RENAME a AS b
| RENAME b AS c

And that:

ROW a=1, b=2
| RENAME
    a AS b, // b=1 ("a" got renamed to "b", "b" is no longer accessible)
    b AS a  // a=1 (the new "b" got renamed to "a" again)

Should first shadow the original b, and finally leave only a.

I've added some comments with what would be the expected result of the CSV tests, and some proposed new tests to cover some potential edge cases.

Also, about the case you comment: row foo = 10, bar = null | rename bar2 as bar2
I would leave it out of this PR. I see you commented on the other issue already; that should be enough for when we want to open a discussion over that topic.

Thank you again! I'll be watching this PR for when a review is needed; tell me if there's something you need

@kanoshiou
Copy link
Contributor Author

Thank you @ivancea for your review and for assisting with the test cases. I've updated the branch, and it would be great if you could review it at your convenience.

@kanoshiou kanoshiou changed the title ESQL: Improve RENAME logic to swap names ESQL: Align RENAME behavior with EVAL for sequential processing Mar 17, 2025
@ivancea ivancea self-assigned this Mar 17, 2025
@ivancea ivancea added the >bug label Mar 17, 2025
@ivancea
Copy link
Contributor

ivancea commented Mar 17, 2025

buildkite test this

@ivancea
Copy link
Contributor

ivancea commented Mar 18, 2025

buildkite test this

@ivancea
Copy link
Contributor

ivancea commented Mar 20, 2025

buildkite test this

@ivancea
Copy link
Contributor

ivancea commented Mar 20, 2025

(Sorry for the repeated commands and merges; there's a failing check and I'm trying to ensure that it's unrelated before merging)

@kanoshiou
Copy link
Contributor Author

@ivancea I believe this issue is unrelated, as it has already been muted by #125305.

Copy link
Contributor

@ivancea ivancea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@ivancea ivancea added v8.19.0 v9.0.1 auto-backport Automatically create backport pull requests when merged labels Mar 20, 2025
@ivancea ivancea merged commit 873827d into elastic:main Mar 20, 2025
17 of 19 checks passed
@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
8.x
9.0

ivancea pushed a commit to ivancea/elasticsearch that referenced this pull request Mar 20, 2025
ivancea pushed a commit to ivancea/elasticsearch that referenced this pull request Mar 20, 2025
elasticsearchmachine pushed a commit that referenced this pull request Mar 21, 2025
…sing (#122250) (#125324)

* ESQL: Align `RENAME` behavior with `EVAL` for sequential processing (#122250)

* Fixed line length on comment for 8.x

---------

Co-authored-by: kanoshiou <[email protected]>
afoucret pushed a commit to afoucret/elasticsearch that referenced this pull request Mar 21, 2025
smalyshev pushed a commit to smalyshev/elasticsearch that referenced this pull request Mar 21, 2025
craigtaverner added a commit to craigtaverner/elasticsearch that referenced this pull request Mar 24, 2025
elasticsearchmachine pushed a commit that referenced this pull request Mar 24, 2025
We shouldn't mutate LogicalPlan.child().output() (or just
LogicalPlan.output()); we did so in RENAME, but only in
EsqlNodeSubclassTest, making them flaky.

>The PR at #122250 seems to
have created a flaky test failure in `EsqlNodeSubclassTests`. Local runs
with `-Dtests.iters=100` lead to about two dozen failures in over 70k
tests run. This is not a high failure rate, but still requires
addressing. > >The single line added to the Analyzer by that PR causes
an `UnsupportedOperationException` on attempting to mutate an immutable
collection when running `EsqlNodeSubclassTests`. It turns out that this
code path comes from `Rename.output()` which is only called in test
scenarios. So a quick fix is to copy the child output into a mutable
collection.
alex-spies added a commit to alex-spies/elasticsearch that referenced this pull request Mar 24, 2025
We shouldn't mutate LogicalPlan.child().output() (or just
LogicalPlan.output()); we did so in RENAME, but only in
EsqlNodeSubclassTest, making them flaky.

>The PR at elastic#122250 seems to
have created a flaky test failure in `EsqlNodeSubclassTests`. Local runs
with `-Dtests.iters=100` lead to about two dozen failures in over 70k
tests run. This is not a high failure rate, but still requires
addressing. > >The single line added to the Analyzer by that PR causes
an `UnsupportedOperationException` on attempting to mutate an immutable
collection when running `EsqlNodeSubclassTests`. It turns out that this
code path comes from `Rename.output()` which is only called in test
scenarios. So a quick fix is to copy the child output into a mutable
collection.
alex-spies added a commit to alex-spies/elasticsearch that referenced this pull request Mar 24, 2025
We shouldn't mutate LogicalPlan.child().output() (or just
LogicalPlan.output()); we did so in RENAME, but only in
EsqlNodeSubclassTest, making them flaky.

>The PR at elastic#122250 seems to
have created a flaky test failure in `EsqlNodeSubclassTests`. Local runs
with `-Dtests.iters=100` lead to about two dozen failures in over 70k
tests run. This is not a high failure rate, but still requires
addressing. > >The single line added to the Analyzer by that PR causes
an `UnsupportedOperationException` on attempting to mutate an immutable
collection when running `EsqlNodeSubclassTests`. It turns out that this
code path comes from `Rename.output()` which is only called in test
scenarios. So a quick fix is to copy the child output into a mutable
collection.
elasticsearchmachine pushed a commit that referenced this pull request Mar 24, 2025
We shouldn't mutate LogicalPlan.child().output() (or just
LogicalPlan.output()); we did so in RENAME, but only in
EsqlNodeSubclassTest, making them flaky.

>The PR at #122250 seems to
have created a flaky test failure in `EsqlNodeSubclassTests`. Local runs
with `-Dtests.iters=100` lead to about two dozen failures in over 70k
tests run. This is not a high failure rate, but still requires
addressing. > >The single line added to the Analyzer by that PR causes
an `UnsupportedOperationException` on attempting to mutate an immutable
collection when running `EsqlNodeSubclassTests`. It turns out that this
code path comes from `Rename.output()` which is only called in test
scenarios. So a quick fix is to copy the child output into a mutable
collection.
elasticsearchmachine pushed a commit that referenced this pull request Mar 24, 2025
We shouldn't mutate LogicalPlan.child().output() (or just
LogicalPlan.output()); we did so in RENAME, but only in
EsqlNodeSubclassTest, making them flaky.

>The PR at #122250 seems to
have created a flaky test failure in `EsqlNodeSubclassTests`. Local runs
with `-Dtests.iters=100` lead to about two dozen failures in over 70k
tests run. This is not a high failure rate, but still requires
addressing. > >The single line added to the Analyzer by that PR causes
an `UnsupportedOperationException` on attempting to mutate an immutable
collection when running `EsqlNodeSubclassTests`. It turns out that this
code path comes from `Rename.output()` which is only called in test
scenarios. So a quick fix is to copy the child output into a mutable
collection.
omricohenn pushed a commit to omricohenn/elasticsearch that referenced this pull request Mar 28, 2025
omricohenn pushed a commit to omricohenn/elasticsearch that referenced this pull request Mar 28, 2025
We shouldn't mutate LogicalPlan.child().output() (or just
LogicalPlan.output()); we did so in RENAME, but only in
EsqlNodeSubclassTest, making them flaky.

>The PR at elastic#122250 seems to
have created a flaky test failure in `EsqlNodeSubclassTests`. Local runs
with `-Dtests.iters=100` lead to about two dozen failures in over 70k
tests run. This is not a high failure rate, but still requires
addressing. > >The single line added to the Analyzer by that PR causes
an `UnsupportedOperationException` on attempting to mutate an immutable
collection when running `EsqlNodeSubclassTests`. It turns out that this
code path comes from `Rename.output()` which is only called in test
scenarios. So a quick fix is to copy the child output into a mutable
collection.
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 >bug external-contributor Pull request authored by a developer outside the Elasticsearch team Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v8.19.0 v9.0.1 v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ES|QL: masking with rename not consistent
5 participants