-
Notifications
You must be signed in to change notification settings - Fork 25.8k
ES|QL: fix null folding of nested COALESCE #140028
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 all commits
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 |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pr: 140028 | ||
| summary: Fix null folding of nested COALESCE | ||
| area: ES|QL | ||
| type: bug | ||
| issues: [] |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -25,7 +25,6 @@ public FoldNull() { | |||||
|
|
||||||
| @Override | ||||||
| public Expression rule(Expression e, LogicalOptimizerContext ctx) { | ||||||
| Expression result = tryReplaceIsNullIsNotNull(e); | ||||||
|
|
||||||
| // convert an aggregate null filter into a false | ||||||
| // perform this early to prevent the rule from converting the null filter into nullifying the whole expression | ||||||
|
|
@@ -36,23 +35,22 @@ public Expression rule(Expression e, LogicalOptimizerContext ctx) { | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| if (result != e) { | ||||||
| return result; | ||||||
| } else if (e instanceof In in) { | ||||||
| if (e instanceof In in) { | ||||||
| if (Expressions.isGuaranteedNull(in.value())) { | ||||||
| return Literal.of(in, null); | ||||||
| } | ||||||
| } else if (e instanceof Alias == false && e.nullable() == Nullability.TRUE | ||||||
| // Non-evaluatable functions stay as a STATS grouping (It isn't moved to an early EVAL like other groupings), | ||||||
| // so folding it to null would currently break the plan, as we don't create an attribute/channel for that null value. | ||||||
| && e instanceof GroupingFunction.NonEvaluatableGroupingFunction == false | ||||||
| && Expressions.anyMatch(e.children(), Expressions::isGuaranteedNull)) { | ||||||
| && e.children().stream().anyMatch(FoldNull::isNull)) { | ||||||
|
Contributor
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. Can this be:
Suggested change
Also, highly optional, streams might be heavy.
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. Unfortunately it doesn't work. We only have to check that the children are not null, not the parent object, otherwise we'll also try to replace literals (it was my first implementation, and it resulted in several failures) |
||||||
| return Literal.of(e, null); | ||||||
| } | ||||||
| return e; | ||||||
| } | ||||||
|
|
||||||
| protected Expression tryReplaceIsNullIsNotNull(Expression e) { | ||||||
|
Contributor
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. 👍 |
||||||
| return e; | ||||||
| private static boolean isNull(Expression e) { | ||||||
| return Expressions.isGuaranteedNull(e) || e.nullable() == Nullability.TRUE && e.children().stream().anyMatch(FoldNull::isNull); | ||||||
| } | ||||||
|
|
||||||
| } | ||||||
Uh oh!
There was an error while loading. Please reload this page.
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.
Old QL code, no longer used