-
Notifications
You must be signed in to change notification settings - Fork 25k
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: Reduce the number of Evals ReplaceMissingFieldWithNull creates #104586
Changes from all commits
ff69a57
027212d
f8f00d0
9ea4d96
800890d
2682ac6
9ec8394
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,6 @@ | ||
pr: 104586 | ||
summary: Reduce the number of Evals `ReplaceMissingFieldWithNull` creates | ||
area: ES|QL | ||
type: bug | ||
issues: | ||
- 104583 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -406,17 +406,25 @@ static class PropagateEvalFoldables extends Rule<LogicalPlan, LogicalPlan> { | |
@Override | ||
public LogicalPlan apply(LogicalPlan plan) { | ||
var collectRefs = new AttributeMap<Expression>(); | ||
// collect aliases | ||
|
||
java.util.function.Function<ReferenceAttribute, Expression> replaceReference = r -> collectRefs.resolve(r, r); | ||
|
||
// collect aliases bottom-up | ||
plan.forEachExpressionUp(Alias.class, a -> { | ||
var c = a.child(); | ||
if (c.foldable()) { | ||
collectRefs.put(a.toAttribute(), c); | ||
boolean shouldCollect = c.foldable(); | ||
// try to resolve the expression based on an existing foldables | ||
if (shouldCollect == false) { | ||
c = c.transformUp(ReferenceAttribute.class, replaceReference); | ||
shouldCollect = c.foldable(); | ||
} | ||
if (shouldCollect) { | ||
collectRefs.put(a.toAttribute(), Literal.of(c)); | ||
Comment on lines
+409
to
+422
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. Why did we need to make changes to 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. Same ^^. Is it to accelerate the resolution? Wouldn't the first 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. Forgot to mention this - while running debugging I've noticed this rule is doing only one transform per run causing the optimizer to run multiple times. So I've modified it so it can do the replacement in one go instead of multiple method calls.
Previously the rule had to run 4 times, now it does it in the first run. |
||
} | ||
}); | ||
if (collectRefs.isEmpty()) { | ||
return plan; | ||
} | ||
java.util.function.Function<ReferenceAttribute, Expression> replaceReference = r -> collectRefs.resolve(r, r); | ||
|
||
plan = plan.transformUp(p -> { | ||
// Apply the replacement inside Filter and Eval (which shouldn't make a difference) | ||
|
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.
Wondering why this wasn't needed so far.
Nit: maybe just calling the function ignoring the return and not shadowing the instance variable might be cleaner.
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 was a bug - the node was mutated but the new instance did not have its dataType()) called.
For example, the node was serialized, deserialized than the execution kicked in - since nobody called dataType(), the value was not initialized throwing a NPE - see the CI failures.