-
Notifications
You must be signed in to change notification settings - Fork 25.6k
ESQL: Fix planning of dangling Project with InlineJoin
#132992
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
Conversation
This fixes a planning error leaving a Project on top of an empty LocalRelation marker unpruned. The empty EmptyRelation is added in the plan as a marker, signaling that the right hand-side of the join can be pruned entirely (and thus the entire InlineJoin).
|
Fixes #132417 (comment) |
interestingly, it fails in CsvTests, but not in EsqlSpecIT, which accepts MIN(MV_COUNT(integer)) as both long and integer type.
|
Pinging @elastic/es-analytical-engine (Team:Analytics) |
| private static LogicalPlan pruneColumnsInProject(Project project, AttributeSet.Builder used) { | ||
| LogicalPlan p = project; | ||
|
|
||
| // A project atop a stub relation will only output attributes which are already part of the INLINEJOIN left-hand side output. |
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 feels brittle in the sense that there may be other rules that might have a different behavior and mess up with the expected pair of steps/actions (1. transform the aggregate in a Project then 2. look for the exact combination Project -> StubRelation) this pruning expects here.
I've had such a solution in my draft PR here but eventually I changed it after reconsidering what is happening in the life of an InlineJoin (basically I considered the flow of the EsqlSession as well, because there are things that are InlineJoin specific and it expects a StubRelation to exist OR the InlineJoin to be pruned completely) and I ended up with this solution instead: https://github.com/elastic/elasticsearch/pull/132934/files#diff-4c0de47236c79e13849f81a2b9765240c822a6af6e90902ba4912f1548c65082R90-R107
Maybe explore a bit more the pruning idea based on what I mentioned above on the idea that the Project + StubRelation you are expecting there might be coming from other rules and mess up the pruning.
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.
Thanks for the review. Generally:
the Project + StubRelation you are expecting there might be coming from other rules
this simplification only happens when the plan has the pattern: InlineJoin - Project - StubRelation. It'll only be problematic if we'll ever have StubRelations on the left hand-side of the InlineJoin. But I guess the verification can be done earlier in the flow, on Aggregate/Project substitution and make the substitution less pattern-dependent.
I'll give it a try.
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.
@astefan, I've taken another approach, simplifying the analysis of the Aggregate iif this is part of an InlineJoin, which allows simplifying the Project analysis downstream too. I think the logic should hold irrespective of InlineJoin being currently only used for INLINESTATS or later modeling other commands too.
The case where an agg on the right hand-side of an InlineJoin was pruned emitted unnecessary nodes in the case when only groups remained available.
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
|
Thanks, Andrei! |
This fixes a planning error leaving a
Projecton top of an emptyLocalRelationmarker unpruned. The emptyEmptyRelationis added in the plan as a marker, signalling that the right hand-side of the join can be pruned entirely (and thus the entireInlineJoin).