Class SchemaAnnotations

java.lang.Object
com.darkcollective.relix.semantic.SchemaAnnotations

public final class SchemaAnnotations extends Object
A mapping from individual RelNode instances to their inferred Schemas.

Keyed by object identity (using an IdentityHashMap), not structural equality. Two relational algebra nodes that are structurally equal but reside at different positions in the tree are tracked independently.

The annotation map is populated during schema inference and is then included in the SemanticModel. Downstream consumers — execution engines, optimizers, IDEs — can query the schema at any node in any RA expression tree without re-running inference.

Usage

   SchemaAnnotations annotations = model.nodeSchemas();
   Schema schema = annotations.get(someNode)
       .orElseThrow(() -> new IllegalStateException("schema not inferred for node"));
 
  • Constructor Details

    • SchemaAnnotations

      public SchemaAnnotations()
      Creates an empty annotation map.
    • SchemaAnnotations

      public SchemaAnnotations(Map<RelNode,Schema> initialEntries)
      Creates an annotation map pre-populated with the supplied entries.

      Entries are keyed by object identity. The caller must supply the exact RelNode instances that will later be looked up via get(RelNode). Useful for constructing test fixtures without running the full schema-inference pipeline.

      Parameters:
      initialEntries - node → schema pairs; must not be null
  • Method Details

    • empty

      public static SchemaAnnotations empty()
      Returns a new empty SchemaAnnotations.
      Returns:
      an empty annotation map
    • get

      public Optional<Schema> get(RelNode node)
      Returns the inferred schema for node, or Optional.empty() if this node was not annotated (e.g. analysis of its subtree failed).
      Parameters:
      node - the RA node to look up
      Returns:
      the schema, or empty
    • require

      public Schema require(RelNode node, String context)
      Returns the inferred schema for node, or throws if the node was never annotated. Use this from consumers (planner, executor, pushdown) that require every node in a fully-inferred tree to carry a schema; the context is appended to the error to identify the calling stage.
      Parameters:
      node - the RA node to look up; must not be null
      context - a short phrase describing the calling stage, e.g. "during SQL pushdown"
      Returns:
      the inferred schema
      Throws:
      IllegalStateException - if node has no annotation
    • hasSchema

      public boolean hasSchema(RelNode node)
      Returns true if a schema has been recorded for node.
      Parameters:
      node - the RA node to test
      Returns:
      whether an annotation exists
    • size

      public int size()
      Returns the number of annotated nodes.
      Returns:
      annotation count
    • asMap

      public Map<RelNode,Schema> asMap()
      Returns an unmodifiable view of the underlying identity map as a standard Map. Useful for iteration in tests or tooling.
      Returns:
      unmodifiable identity map