Class RuleUtils
java.lang.Object
org.elasticsearch.xpack.esql.optimizer.rules.RuleUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic Tuple<List<Alias>, List<NamedExpression>> aliasedNulls(List<Attribute> outputAttributes, Predicate<Attribute> shouldBeReplaced) static AttributeMap<Expression> Collects references to foldable expressions from the given logical plan, returning anAttributeMapthat maps foldable aliases to their corresponding literal values.static AttributeMap<Expression> foldableReferencesSkipMVGroupings(LogicalPlan plan, LogicalOptimizerContext ctx, Predicate<LogicalPlan> stopCondition) Collects references to foldable expressions from the given logical plan, returning anAttributeMapthat maps foldable aliases to their corresponding literal values.
-
Method Details
-
aliasedNulls
public static Tuple<List<Alias>,List<NamedExpression>> aliasedNulls(List<Attribute> outputAttributes, Predicate<Attribute> shouldBeReplaced) - Parameters:
outputAttributes- The original output attributes.shouldBeReplaced- A predicate to determine which attributes should be replaced with null aliases.- Returns:
- a tuple of two lists:
- A list of aliases to null literals for those data types in the
outputAttributesthatshouldBeReplaced. - A list of named expressions where attributes that match the predicate are replaced with their corresponding null alias.
- A list of aliases to null literals for those data types in the
-
foldableReferencesSkipMVGroupings
public static AttributeMap<Expression> foldableReferencesSkipMVGroupings(LogicalPlan plan, LogicalOptimizerContext ctx) Collects references to foldable expressions from the given logical plan, returning anAttributeMapthat maps foldable aliases to their corresponding literal values. Equivalent to callingfoldableReferencesSkipMVGroupings(LogicalPlan, LogicalOptimizerContext, Predicate)with a predicate that never stops.- Parameters:
plan- The logical plan to analyze.ctx- The optimizer context providing fold context.- Returns:
- An
AttributeMapcontaining foldable references and their literal values.
-
foldableReferencesSkipMVGroupings
public static AttributeMap<Expression> foldableReferencesSkipMVGroupings(LogicalPlan plan, LogicalOptimizerContext ctx, Predicate<LogicalPlan> stopCondition) Collects references to foldable expressions from the given logical plan, returning anAttributeMapthat maps foldable aliases to their corresponding literal values.Traverses plan nodes bottom-up. At
Aggregateboundaries, multi-valued grouping keys are removed from the collected references — after GROUP BY, these attributes represent expanded single values, not the original multi-valued literals. This prevents resolving post-Aggregate expressions against stale multi-valued literals, which would produce spurious warnings and incorrect fold results.Note: this MV-grouping removal is applied only at
Aggregateboundaries, not atInlineJoinboundaries (i.e.INLINE STATS). ForINLINE STATS, the join key is always the grouping, and callers are responsible for excludingInlineJoinplans before calling this method — seePruneLeftJoinOnNullMatchingFieldfor an example of that explicit exclusion.- Parameters:
plan- The logical plan to analyze.ctx- The optimizer context providing fold context.stopCondition- A predicate that, when it returnstruefor a plan node, halts traversal into that node and its subtree.- Returns:
- An
AttributeMapcontaining foldable references and their literal values.
-