Record Class SemanticModel
- Record Components:
namespace- the root file's namespace; defaults to"default"symbolTable- the populated symbol table; must not be nullsources- canonical name → full source declaration; must not be nullconnections- canonical name → database connection declaration; must not be nullstatistics- canonical name → relation statistics; must not be nullnodeSchemas- per-node inferred schemas; must not be nullschemaGraph- the schema relationship graph; must not be nullrootQueries- ordered query statements from the root file; must not be nullfunctions- the catalogue every function call was resolved against; must not be null
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
.relixfile, or"default"if nonamespacestatement 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
sourcedeclaration reachable from the root file, keyed by the lower-cased canonical name. ThesymbolTable()contains the correspondingSourceRelationSymbolfor 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 assources(). 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
relatestatements andreferences:blocks and validated against the inferred schemas, merged with any supplemental (session-learned) edges supplied to the analyzer.SchemaGraph.EMPTYwhen nothing is declared. rootQueries()- The ordered list of
querystatements 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 Summary
ConstructorsConstructorDescriptionSemanticModel(String namespace, SymbolTable symbolTable, Map<String, SourceDeclaration> sources, SchemaAnnotations nodeSchemas, List<QueryStatement> rootQueries) Backward-compatible constructor for models with no database connections.SemanticModel(String namespace, SymbolTable symbolTable, Map<String, SourceDeclaration> sources, Map<String, ConnectionDeclaration> connections, SchemaAnnotations nodeSchemas, List<QueryStatement> rootQueries) Convenience constructor for models with connections but no statistics.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) Creates an instance of aSemanticModelrecord class.SemanticModel(String namespace, SymbolTable symbolTable, Map<String, SourceDeclaration> sources, Map<String, ConnectionDeclaration> connections, Map<String, RelationStatistics> statistics, SchemaAnnotations nodeSchemas, List<QueryStatement> rootQueries) Convenience constructor for models with no schema graph; the graph defaults toSchemaGraph.EMPTYandfunctions()to the installed libraries. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of theconnectionsrecord component.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.final booleanIndicates whether some other object is "equal to" this one.Returns the value of thefunctionsrecord component.final inthashCode()Returns a hash code value for this object.ir()This model as a readable report: every symbol with its heading, the expression tree behind each view, and the root queries.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.Returns the value of thenamespacerecord component.Returns the value of thenodeSchemasrecord component.resolveJoins(RelNode expression) Resolves the joins inexpressionover 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.Returns the value of therootQueriesrecord component.Returns the value of theschemaGraphrecord component.sources()Returns the value of thesourcesrecord component.Returns the value of thestatisticsrecord component.Returns the value of thesymbolTablerecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
SemanticModel
public 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) Creates an instance of aSemanticModelrecord class.- Parameters:
namespace- the value for thenamespacerecord componentsymbolTable- the value for thesymbolTablerecord componentsources- the value for thesourcesrecord componentconnections- the value for theconnectionsrecord componentstatistics- the value for thestatisticsrecord componentnodeSchemas- the value for thenodeSchemasrecord componentschemaGraph- the value for theschemaGraphrecord componentrootQueries- the value for therootQueriesrecord componentfunctions- the value for thefunctionsrecord component
-
SemanticModel
public SemanticModel(String namespace, SymbolTable symbolTable, Map<String, SourceDeclaration> sources, Map<String, ConnectionDeclaration> connections, Map<String, RelationStatistics> statistics, SchemaAnnotations nodeSchemas, List<QueryStatement> rootQueries) Convenience constructor for models with no schema graph; the graph defaults toSchemaGraph.EMPTYandfunctions()to the installed libraries.- Parameters:
namespace- the root file's namespacesymbolTable- the populated symbol tablesources- canonical name → source declarationconnections- canonical name → connection declarationstatistics- canonical name → relation statisticsnodeSchemas- per-node inferred schemasrootQueries- ordered query statements from the root file
-
SemanticModel
public SemanticModel(String namespace, SymbolTable symbolTable, Map<String, SourceDeclaration> sources, Map<String, ConnectionDeclaration> connections, SchemaAnnotations nodeSchemas, List<QueryStatement> rootQueries) Convenience constructor for models with connections but no statistics.- Parameters:
namespace- the root file's namespacesymbolTable- the populated symbol tablesources- canonical name → source declarationconnections- canonical name → connection declarationnodeSchemas- per-node inferred schemasrootQueries- ordered query statements from the root file
-
SemanticModel
public SemanticModel(String namespace, SymbolTable symbolTable, Map<String, SourceDeclaration> sources, SchemaAnnotations nodeSchemas, List<QueryStatement> rootQueries) Backward-compatible constructor for models with no database connections.- Parameters:
namespace- the root file's namespacesymbolTable- the populated symbol tablesources- canonical name → source declarationnodeSchemas- per-node inferred schemasrootQueries- ordered query statements from the root file
-
-
Method Details
-
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.relationshipslearns the joins its user has written, so a laterresolveJoins(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
Resolves the joins inexpressionover 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
Passthroughwhen the graph cannot improve on the expression (there is no graph, or the expression is not a join over base relations the graph connects),Resolvedwhen exactly one minimal path connects the relations, andAmbiguouswhen 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
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
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 forir(). 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
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. -
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. -
equals
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 withObjects::equals(Object,Object). -
namespace
Returns the value of thenamespacerecord component.- Returns:
- the value of the
namespacerecord component
-
symbolTable
Returns the value of thesymbolTablerecord component.- Returns:
- the value of the
symbolTablerecord component
-
sources
Returns the value of thesourcesrecord component.- Returns:
- the value of the
sourcesrecord component
-
connections
Returns the value of theconnectionsrecord component.- Returns:
- the value of the
connectionsrecord component
-
statistics
Returns the value of thestatisticsrecord component.- Returns:
- the value of the
statisticsrecord component
-
nodeSchemas
Returns the value of thenodeSchemasrecord component.- Returns:
- the value of the
nodeSchemasrecord component
-
schemaGraph
Returns the value of theschemaGraphrecord component.- Returns:
- the value of the
schemaGraphrecord component
-
rootQueries
Returns the value of therootQueriesrecord component.- Returns:
- the value of the
rootQueriesrecord component
-
functions
Returns the value of thefunctionsrecord component.- Returns:
- the value of the
functionsrecord component
-