Package org.elasticsearch.xpack.esql.optimizer.rules.logical
package org.elasticsearch.xpack.esql.optimizer.rules.logical
-
ClassDescriptionThis rule must always be placed after
LiteralsOnTheRightsince it looks at TRUE/FALSE literals' existence on the right hand-side of theEquals/NotEqualsexpressions.Combine disjunctive Equals, In or CIDRMatch expressions on the same field into an In or CIDRMatch expression.Combine multiple Evals into one in order to reduce the number of nodes in a plan.Extract a per-function expression filter applied to all the aggs as a queryFilter, when no groups are provided.OptimizerRules.OptimizerExpressionRule<E extends Expression>OptimizerRules.OptimizerRule<SubPlan extends LogicalPlan>Fold the arms ofCASEstatements.Propagate Equals to eliminate conjuncted Ranges or BinaryComparisons.Replace any reference attribute with its source, if it does not affect the result.Replace any evaluation from the inlined aggregation side (right side) to the left side (source) to perform the matching.Merges unmapped fields into the output of the ES relation.Remove unused columns created in the plan, in fields inside eval or aggregations inside stats.SORT cannot be executed without a LIMIT, as ES|QL doesn't support unbounded sort (yet).RemovesAggregateoverrides in grouping, aggregates and across them inside.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 xbecomesSTATS BY x | EVAL a = x + 1 | KEEP a, xAnd 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, gReplace nested expressions inside aAggregatewith synthetic eval.Replace aliasing evals (eval x=a) with a projection which can be further combined / simplified.Replaces an aggregation function having a false/null filter with an EVAL node.Replace type converting eval with aliasing eval when type change does not occur.Simplifies arithmetic expressions with BinaryComparisons and fixed point fields, such as: (int + 2) / 3 > 4 => int > 103 in (field, 4, 5) --> 3 in (field) or 3 in (4, 5)This rule should not be needed - the substitute infrastructure should be enough.Currently this works similarly to SurrogateExpression, leaving the logic inside the expressions, so each can decide for itself whether or not to change to a surrogate expression.Rate aggregation is special because it must be computed per time series, regardless of the grouping keys.