java.lang.Object
org.elasticsearch.xpack.esql.optimizer.rules.RuleUtils

public final class RuleUtils extends Object
  • 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:
      1. A list of aliases to null literals for those data types in the outputAttributes that shouldBeReplaced.
      2. A list of named expressions where attributes that match the predicate are replaced with their corresponding null alias.
    • foldableReferencesSkipMVGroupings

      public static AttributeMap<Expression> foldableReferencesSkipMVGroupings(LogicalPlan plan, LogicalOptimizerContext ctx)
      Collects references to foldable expressions from the given logical plan, returning an AttributeMap that maps foldable aliases to their corresponding literal values. Equivalent to calling foldableReferencesSkipMVGroupings(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 AttributeMap containing 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 an AttributeMap that maps foldable aliases to their corresponding literal values.

      Traverses plan nodes bottom-up. At Aggregate boundaries, 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 Aggregate boundaries, not at InlineJoin boundaries (i.e. INLINE STATS). For INLINE STATS, the join key is always the grouping, and callers are responsible for excluding InlineJoin plans before calling this method — see PruneLeftJoinOnNullMatchingField for 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 returns true for a plan node, halts traversal into that node and its subtree.
      Returns:
      An AttributeMap containing foldable references and their literal values.