Skip to content
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: Fix bug when combining projections #107131

Merged
merged 3 commits into from
Apr 5, 2024
Merged

Conversation

costin
Copy link
Member

@costin costin commented Apr 5, 2024

Recursive aliases (eval x = 1, x1 = x) were not taken into account when
combining projections causing the target field to be lost (and only the
immediate intermediate named expression to be used instead which became
invalid).

Fix #107083

Recursive aliases (eval x = 1, x1 = x) were not taken into account when
 combining projections causing the target field to be lost (and only the
 immediate intermediate named expression to be used instead which became
 invalid).

Fix elastic#107083
@costin costin self-assigned this Apr 5, 2024
@elasticsearchmachine elasticsearchmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Apr 5, 2024
@elasticsearchmachine
Copy link
Collaborator

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

@elasticsearchmachine
Copy link
Collaborator

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

Copy link
Contributor

@alex-spies alex-spies left a comment

Choose a reason for hiding this comment

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

I think this looks good, only minor remarks - except one potentially non optimal pruning in an added test, but that shouldn't block this

@@ -1550,3 +1550,37 @@ s2point1:d | s_mv:i | languages:i
2.1 | 3 | 5
2.1 | 3 | null
;

evalOverridingKey
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't this also need a skip for pre 8.14?

assertThat(Expressions.names(keep.projections()), contains("last_name", "f2", "f4"));
var eval = as(keep.child(), Eval.class);
assertThat(Expressions.names(eval.fields()), contains("f4"));
var add = as(Alias.unwrap(eval.fields().get(0)), Add.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should assert that the summands are language and 3.

Comment on lines +418 to +419
* \_Aggregate[[last_name{f}#23, first_name{f}#20, k{r}#4],[SUM(salary{f}#24) AS s, last_name{f}#23, first_name{f}#20, first_n
* ame{f}#20 AS k]]
Copy link
Contributor

Choose a reason for hiding this comment

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

Potentially out of scope, but: couldn't/shouldn't we prune k from the groupings, since it's an alias for first_name? k doesn't seem to be used in the aggregates, either.

Copy link
Member Author

Choose a reason for hiding this comment

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

See #107166

Comment on lines +429 to +432
// collect named expressions declaration in the lower list
AttributeMap<NamedExpression> namedExpressions = new AttributeMap<>();
// while also collecting the alias map for resolving the source (f1 = 1, f2 = f1, etc..)
AttributeMap<Expression> aliases = new AttributeMap<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: comments/var names here are a bit hard to follow.

Copy link
Contributor

@astefan astefan left a comment

Choose a reason for hiding this comment

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

LGTM

@costin costin added the auto-backport-and-merge Automatically create backport pull requests and merge when ready label Apr 5, 2024
@costin costin merged commit a9388e1 into elastic:main Apr 5, 2024
14 checks passed
@costin costin deleted the fix/107083 branch April 5, 2024 17:16
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
8.13 Commit could not be cherrypicked due to conflicts

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 107131

costin added a commit to costin/elasticsearch that referenced this pull request Apr 5, 2024
Recursive aliases (eval x = 1, x1 = x) were not taken into account when
 combining projections causing the target field to be lost (and only the
 immediate intermediate named expression to be used instead which became
 invalid).

Fix elastic#107083

(cherry picked from commit a9388e1)
@costin
Copy link
Member Author

costin commented Apr 5, 2024

Raised #107167 for backport

elasticsearchmachine pushed a commit that referenced this pull request Apr 5, 2024
Recursive aliases (eval x = 1, x1 = x) were not taken into account when
 combining projections causing the target field to be lost (and only the
 immediate intermediate named expression to be used instead which became
 invalid).

Fix #107083

(cherry picked from commit a9388e1)
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-and-merge Automatically create backport pull requests and merge when ready backport pending >bug Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v8.13.2 v8.14.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DROP of EVAL planning issues
4 participants