Class ReplaceAggregateAggExpressionWithEval
java.lang.Object
org.elasticsearch.xpack.esql.rule.Rule<Aggregate,LogicalPlan>
org.elasticsearch.xpack.esql.optimizer.rules.logical.OptimizerRules.OptimizerRule<Aggregate>
org.elasticsearch.xpack.esql.optimizer.rules.logical.ReplaceAggregateAggExpressionWithEval
public final class ReplaceAggregateAggExpressionWithEval
extends OptimizerRules.OptimizerRule<Aggregate>
Replace nested expressions over aggregates with synthetic eval post the aggregation
stats a = sum(a) + min(b) by x
becomes
stats a1 = sum(a), a2 = min(b) by x | eval a = a1 + a2 | keep a, x
The rule also considers expressions applied over groups:
STATS a = x + 1 BY x becomes STATS BY x | EVAL a = x + 1 | KEEP a, x
And to combine the two:
stats a = x + count(*) by x
becomes
stats a1 = count(*) by x | eval a = x + a1 | keep a1, x
Since the logic is very similar, this rule also handles duplicate aggregate functions to avoid duplicate compute
stats a = min(x), b = min(x), c = count(*), d = count() by g
becomes
stats a = min(x), c = count(*) by g | eval b = a, d = c | keep a, b, c, d, g-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Methods inherited from class org.elasticsearch.xpack.esql.optimizer.rules.logical.OptimizerRules.OptimizerRule
apply
-
Constructor Details
-
ReplaceAggregateAggExpressionWithEval
public ReplaceAggregateAggExpressionWithEval()
-
-
Method Details
-
rule
- Specified by:
rulein classOptimizerRules.OptimizerRule<Aggregate>
-