java.lang.Object
org.elasticsearch.xpack.esql.rule.Rule<LogicalPlan,LogicalPlan>
org.elasticsearch.xpack.esql.optimizer.rules.logical.local.InferIsNotNull

public class InferIsNotNull extends Rule<LogicalPlan,LogicalPlan>
Simplify IsNotNull targets by resolving the underlying expression to its root fields. e.g. (x + 1) / 2 IS NOT NULL --> x IS NOT NULL AND (x+1) / 2 IS NOT NULL SUBSTRING(x, 3) > 4 IS NOT NULL --> x IS NOT NULL AND SUBSTRING(x, 3) > 4 IS NOT NULL When dealing with multiple fields, a conjunction/disjunction based on the predicate: (x + y) / 4 IS NOT NULL --> x IS NOT NULL AND y IS NOT NULL AND (x + y) / 4 IS NOT NULL This handles the case of fields nested inside functions or expressions in order to avoid: - having to evaluate the whole expression - not pushing down the filter due to expression evaluation IS NULL cannot be simplified since it leads to a disjunction which prevents the filter to be pushed down: (x + 1) IS NULL --> x IS NULL OR x + 1 IS NULL and x IS NULL cannot be pushed down
Implementation-wise this rule goes bottom-up, keeping an alias up to date to the current plan and then looks for replacing the target.