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

public final class RuleUtils extends Object
  • Method Details

    • aliasedNulls

      public static org.elasticsearch.core.Tuple<List<Alias>,List<NamedExpression>> aliasedNulls(List<Attribute> outputAttributes, Predicate<Attribute> shouldBeReplaced)
      Returns a tuple of two lists: 1. A list of aliases to null literals for those data types in the that . 2. A list of named expressions where attributes that match the predicate are replaced with their corresponding null alias.
      Parameters:
      outputAttributes - The original output attributes.
      shouldBeReplaced - A predicate to determine which attributes should be replaced with null aliases.
    • 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.

      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.
      Returns:
      An AttributeMap containing foldable references and their literal values.