Record Class SemanticModel

java.lang.Object
java.lang.Record
com.darkcollective.relix.semantic.SemanticModel
Record Components:
namespace - the root file's namespace; defaults to "default"
symbolTable - the populated symbol table; must not be null
sources - canonical name → full source declaration; must not be null
connections - canonical name → database connection declaration; must not be null
statistics - canonical name → relation statistics; must not be null
nodeSchemas - per-node inferred schemas; must not be null
schemaGraph - the schema relationship graph; must not be null
rootQueries - ordered query statements from the root file; must not be null
functions - the catalogue every function call was resolved against; must not be null

public record SemanticModel(String namespace, SymbolTable symbolTable, Map<String,SourceDeclaration> sources, Map<String,ConnectionDeclaration> connections, Map<String,RelationStatistics> statistics, SchemaAnnotations nodeSchemas, SchemaGraph schemaGraph, List<QueryStatement> rootQueries, FunctionCatalog functions) extends Record
The validated in-memory representation produced by a successful (or partially-successful) semantic analysis run.

A SemanticModel is always returned inside a SemanticResult. When the analysis encountered non-fatal errors the model reflects what could be determined up to the first unrecoverable failure for each file; callers should inspect SemanticResult.errors() before treating the model as authoritative.

Contents

namespace()
The namespace declared in the root .relix file, or "default" if no namespace statement was present.
symbolTable()
The fully-populated symbol table, containing built-ins, imported symbols, and all declarations from the root file. Backed by an InMemorySymbolTable.
sources()
Full source configuration for every source declaration reachable from the root file, keyed by the lower-cased canonical name. The symbolTable() contains the corresponding SourceRelationSymbol for schema-lookup purposes; this map provides the transport-level detail needed at execution time.
nodeSchemas()
Per-node schema annotations for every relational algebra tree that was successfully inferred. Execution engines and optimizers may query the inferred schema at any node without re-running inference.
statistics()
Optional per-relation statistics (row counts, keys) gathered from a CatalogProvider, keyed by the same lower-cased canonical name as sources(). Consumed by the cost model; a relation absent from this map simply has no statistics.
schemaGraph()
The schema graph: declared relationship edges between relations, assembled from relate statements and references: blocks and validated against the inferred schemas, merged with any supplemental (session-learned) edges supplied to the analyzer. SchemaGraph.EMPTY when nothing is declared.
rootQueries()
The ordered list of query statements in the root file; these are the top-level outputs the user requested.
functions()
The functions this model was analysed against — the catalogue the analyser resolved every call in it through. It travels with the model because every later phase asks the same questions of a function that analysis did (what it returns, whether it may be folded, how a backend spells it), and two separately-built catalogues can disagree about what a name means.
  • Constructor Details

  • Method Details

    • demonstratedRelationships

      public List<Relationship> demonstratedRelationships()
      The relationships this analysis demonstrates that its schema graph does not already record: each column equality written across the two sides of a join, in a query or a view, over relations the graph could connect.

      A session that feeds these back through Relix.Builder.relationships learns the joins its user has written, so a later resolveJoins(com.darkcollective.relix.ast.RelNode) can assemble the same join unprompted. Nothing is executed: an analysis alone says which columns a join equated. Only a model without errors is worth asking, since a query that did not resolve demonstrates nothing.

      Returns:
      the distinct edges, in the order first written, each with a generated name and origin LEARNED; never null, possibly empty
      Since:
      1.0
    • resolveJoins

      public JoinResolution resolveJoins(RelNode expression)
      Resolves the joins in expression over this model's schema graph: the join is assembled from the relationships the graph records, rather than from the conditions the expression was written with.

      The answer is Passthrough when the graph cannot improve on the expression (there is no graph, or the expression is not a join over base relations the graph connects), Resolved when exactly one minimal path connects the relations, and Ambiguous when several do, listing them by relationship name so a user can be asked which was meant.

      Parameters:
      expression - the expression whose joins to resolve; must not be null
      Returns:
      the resolution; never null
      Since:
      1.0
    • ir

      public String ir()
      This model as a readable report: every symbol with its heading, the expression tree behind each view, and the root queries.

      Lines are at most 80 characters, so the report prints cleanly in a terminal.

      Returns:
      the report; never null or empty
      Since:
      1.0
    • ir

      public String ir(Collection<String> relations)
      The report limited to the named relations: their symbols and expression trees, with every other relation and all functions left out. The root queries are shown as for ir(). Names match case-insensitively.

      A tool showing the tree behind one query passes the relations that query reaches, rather than printing the whole script.

      Parameters:
      relations - the relations to include; must not be null
      Returns:
      the report; never null or empty
      Since:
      1.0
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • namespace

      public String namespace()
      Returns the value of the namespace record component.
      Returns:
      the value of the namespace record component
    • symbolTable

      public SymbolTable symbolTable()
      Returns the value of the symbolTable record component.
      Returns:
      the value of the symbolTable record component
    • sources

      public Map<String,SourceDeclaration> sources()
      Returns the value of the sources record component.
      Returns:
      the value of the sources record component
    • connections

      public Map<String,ConnectionDeclaration> connections()
      Returns the value of the connections record component.
      Returns:
      the value of the connections record component
    • statistics

      public Map<String,RelationStatistics> statistics()
      Returns the value of the statistics record component.
      Returns:
      the value of the statistics record component
    • nodeSchemas

      public SchemaAnnotations nodeSchemas()
      Returns the value of the nodeSchemas record component.
      Returns:
      the value of the nodeSchemas record component
    • schemaGraph

      public SchemaGraph schemaGraph()
      Returns the value of the schemaGraph record component.
      Returns:
      the value of the schemaGraph record component
    • rootQueries

      public List<QueryStatement> rootQueries()
      Returns the value of the rootQueries record component.
      Returns:
      the value of the rootQueries record component
    • functions

      public FunctionCatalog functions()
      Returns the value of the functions record component.
      Returns:
      the value of the functions record component