Class DeclaredSchemaResolver

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

public final class DeclaredSchemaResolver extends Object
Bridges a DatasetMapping (the String-typed, server-side declaration) into the ES|QL currency the external-source resolver speaks: Attributes typed with DataType, plus the logical→physical rename map. This is the one place the declared type String becomes a DataType; everything downstream (planner, reader, output) sees logical names only.

Used by the resolver for both supply modes: in strict mode (dynamic: false) declaredAttributes(org.elasticsearch.cluster.metadata.DatasetMapping) is the entire resolved schema (no file is read); in non-strict mode the declared attributes overlay (and beat) the inferred ones of the same column. The renameMap(org.elasticsearch.cluster.metadata.DatasetMapping) rides the typed DeclaredReadSpec to the data node and is consumed at the reader-facing boundaries via PhysicalNames; ColumnMapping/reconciliation stay in logical space. It carries only renamed columns.

  • Method Details

    • declaredAttributes

      public static List<Attribute> declaredAttributes(DatasetMapping mapping)
      The declared columns as ES|QL attributes, keyed by logical name and in declaration order. Returns an empty list when there is no mappings block (an _id-only mappings block contributes no columns).
    • renameMap

      public static Map<String,String> renameMap(DatasetMapping mapping)
      Logical→physical name map for the columns that declare a path move (logical name ≠ physical name). Empty when nothing renames. The map is 1:1 (a physical is claimed by at most one logical — validation enforces it), so its PhysicalNames.inverse(java.util.Map<java.lang.String, java.lang.String>) is well-defined. PhysicalNames uses this at the last-mile reader-facing boundaries; the reader and ColumnMapping stay rename-agnostic.
    • overlayNonStrict

      public static DeclaredSchemaResolver.Overlaid overlayNonStrict(List<Attribute> inferred, DatasetMapping mapping)
      Apply a non-strict (dynamic: true) mapping over an inferred schema: every declared column overrides the inferred column of the same physical name — renamed to its logical name and pinned to its declared type — while undeclared inferred columns pass through unchanged. A declared column whose physical name is absent from the inferred schema is an error (it references a column the source does not have).
    • overlayNonStrict

      public static DeclaredSchemaResolver.Overlaid overlayNonStrict(List<Attribute> inferred, DatasetMapping mapping, boolean lenient)
      As overlayNonStrict(List, DatasetMapping) but lenient controls the unmatched-declared-column policy: strict (false) errors when a declared column is absent from inferred (used against the unified schema, where every declared column must appear); lenient (true) skips it (used per-file, where a column may legitimately be absent from one file under union-by-name).