ES|QL: fix null folding of nested COALESCE#140028
Merged
luigidellaquila merged 3 commits intoelastic:mainfrom Dec 30, 2025
Merged
ES|QL: fix null folding of nested COALESCE#140028luigidellaquila merged 3 commits intoelastic:mainfrom
luigidellaquila merged 3 commits intoelastic:mainfrom
Conversation
Collaborator
|
Pinging @elastic/es-analytical-engine (Team:Analytics) |
Collaborator
|
Hi @luigidellaquila, I've created a changelog YAML for you. |
luigidellaquila
commented
Dec 30, 2025
| } | ||
| } | ||
|
|
||
| if (result != e) { |
Contributor
Author
There was a problem hiding this comment.
Old QL code, no longer used
mouhc1ne
reviewed
Dec 30, 2025
|
|
||
| foldCoalesce | ||
| required_capability: fix_fold_coalesce | ||
| ROW x = null| EVAL append_coalesce = MV_APPEND("2", COALESCE(x, "1")) |
bpintea
reviewed
Dec 30, 2025
| // 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.
Can this be:
Suggested change
| && e.children().stream().anyMatch(FoldNull::isNull)) { | |
| isNull(e)) { |
Also, highly optional, streams might be heavy.
Contributor
Author
There was a problem hiding this comment.
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)
bpintea
reviewed
Dec 30, 2025
| return e; | ||
| } | ||
|
|
||
| protected Expression tryReplaceIsNullIsNotNull(Expression e) { |
bpintea
reviewed
Dec 30, 2025
|
|
||
| foldCoalesce | ||
| required_capability: fix_fold_coalesce | ||
| ROW x = null| EVAL append_coalesce = MV_APPEND("2", COALESCE(x, "1")) |
Contributor
There was a problem hiding this comment.
Maybe an extra test with a NULL literal?
bpintea
approved these changes
Dec 30, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
COALESCE can't be folded if one of the children is null, even if it's nested inside other expressions.
The same applies to all the functions that don't have
Nullability.TRUE(eg.CaseandMvUnion)Fixes: #139344