Class FilterAdaptation

java.lang.Object
org.elasticsearch.xpack.esql.datasources.FilterAdaptation

public final class FilterAdaptation extends Object
Format-agnostic utility for adapting pushed filter expressions to a specific file's column set.

In UNION_BY_NAME scenarios, different files may have different columns. When a pushed filter references a column absent from a file, the predicate must be simplified before re-translation to the format-specific filter (Parquet FilterPredicate, ORC SearchArgument).

Adaptation rules for missing columns (SQL three-valued logic):

  • Value comparison on missing column → UNKNOWN → FALSE in WHERE → remove conjunct
  • IS NULL on missing column → TRUE (all rows match) → remove conjunct (always true)
  • IS NOT NULL on missing column → FALSE → remove conjunct (entire AND is false)
  • AND(A, B): if either is null (FALSE) → null; if either is TRUE → other side
  • OR(A, B): if either is TRUE → TRUE; if one is null → other side
  • NOT(child): if child is null → TRUE; if child is TRUE → null

RECHECK semantics guarantee correctness: the adapted filter only affects I/O optimization (row-group/stripe skipping), never row-level correctness.

  • Method Details

    • adaptFilterForFile

      public static List<Expression> adaptFilterForFile(List<Expression> filterConjuncts, Set<String> fileColumnNames)
      Adapts pushed filter conjuncts for a specific file's column set. Removes or simplifies predicates on columns absent from the file.
      Parameters:
      filterConjuncts - AND-separated pushed expressions (same contract as FilterPushdownSupport.pushFilters(java.util.List<org.elasticsearch.xpack.esql.core.expression.Expression>) input)
      fileColumnNames - names of columns present in this file's schema
      Returns:
      adapted conjuncts; empty list means no pushdown for this file
    • adaptFilterForFile

      public static List<Expression> adaptFilterForFile(List<Expression> filterConjuncts, Set<String> fileColumnNames, Map<String,DataType> fileColumnTypes)
      Adapts pushed filter conjuncts for a specific file's column set and types. Handles both missing columns and type-widened columns.

      When a column exists in the file with a narrower type than the unified schema (e.g., INTEGER in file vs LONG in unified), filter literals are downcast to the file's native type for optimal row-group/stripe skipping. Literals that overflow the narrower range are statically resolved based on the comparison operator.

      Parameters:
      filterConjuncts - AND-separated pushed expressions
      fileColumnNames - names of columns present in this file's schema
      fileColumnTypes - file-local types for columns that differ from the unified schema; columns not in this map are assumed to match the unified type
      Returns:
      adapted conjuncts; empty list means no pushdown for this file