Class ScriptBuilders
Script authoring surface — the statement-level half of the AST contract,
for tests and embedders that assemble a whole script without the .relix grammar.
SemanticAnalyzer.analyze(Script, rootPath) is the engine's front door, so a
caller who can build a Script needs no parser at all. These factories are how
that is done readably, and ScriptBuilderCoverageTest fails the build if a new
Statement or SourceConfig kind arrives without one.
It extends AstBuilders, so one extends ScriptBuilders
— or a static import of this class — reaches the relational factories too:
Script script = script(
source("Orders", csvSource("orders.csv", column("id", ScalarType.NUMBER))),
assign("Open", select(cmp(attr("status"), ComparisonOperator.EQUAL, str("OPEN")),
rel("Orders"))),
query("Open"));
The same rule as AstBuilders applies: a factory takes the record's own
components in the record's own order, minus SourceLocation, which defaults to
SourceLocation.UNKNOWN. Statements that carry an exported flag get a
two-form treatment — the short factory is the un-exported common case, and an explicit
overload takes the flag.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ArrayTypeAn array type overelement.static AssignmentStatementA view binding, exported or not.static AssignmentStatementassign(boolean exported, String name, InlineTable table) An inline-table binding, exported or not.static AssignmentStatementName := { <expression> };— a view binding.static AssignmentStatementassign(String name, InlineTable table) Name := [ … ];— an inline-table binding.static ColumnSpeccolumn(String name, ScalarType type) An output column of a source schema.static ColumnSpeccolumn(String name, ScalarType type, String path) An output column bound to an extraction path.static ColumnSpecAn output column of a nested type — a struct, or an array of anything.static ConnectionDeclarationconnection, exported or not.static ConnectionDeclarationconnection(String name, DatabaseConnectionConfig config) connection <name> from jdbc { url: … }— the JDBC shorthand the record itself offers, exported.static ConnectionDeclarationconnection <name> from <type> { … }.static ConnectionTableSourceConfigconnectionTable(String connection, String table, ColumnSpec... columns) from <connection>.<table>.static ConnectionTableSourceConfigconnectionTable(String connection, String table, List<ColumnSpec> columns, List<ColumnReference> references) from <connection>.<table> { references: { … } }.static CsvFileSourceConfigcsvSource(String path, boolean hasHeader, List<ColumnSpec> columns) from csv { … }, header row optional.static CsvFileSourceConfigcsvSource(String path, boolean hasHeader, List<ColumnSpec> columns, List<ColumnReference> references) from csv { …, references: { … } }.static CsvFileSourceConfigcsvSource(String path, ColumnSpec... columns) from csv { … }with a header row.static CsvInlineTableA CSV inline table.static DatabaseSourceConfigdatabaseSource(String url, String table, ColumnSpec... columns) from database { url: …, table: … }.static DatabaseSourceConfigdatabaseSource(String url, String table, List<ColumnSpec> columns, List<ColumnReference> references) from database { …, references: { … } }.static DefStatementdef(boolean exported, String name, List<ParameterDefinition> parameters, ScalarType returnType, Operand body) A scalardef, exported or not.static DefStatementdef(String name, List<ParameterDefinition> parameters, ScalarType returnType, Operand body) def <name>(…): <type> = <operand>— a scalar function.static DefRelationStatementdefRelation(boolean exported, String name, List<ParameterDefinition> parameters, RelNode body) A relationdef, exported or not.static DefRelationStatementdefRelation(String name, List<ParameterDefinition> parameters, RelNode body) def relation <name>(…) = { … }— a table-valued function.static EndpointSpecAn endpoint of arelate, with the default[0..*]bounds.static EndpointSpecendpoint(String relationRef, List<String> columns, long min, OptionalLong max) An endpoint with explicit cardinality bounds.static EnvStatementenv()envwith the default file and no active environment.static EnvStatementenv "<file>" [as <name>].static StructType.FieldA struct field, for building a nested column type.static GeneratorSourceConfiggeneratorSource(String generatorName, Map<String, String> args) from generator <name> { … }.static HttpSourceConfighttpSource(String url, ColumnSpec... columns) from http { … }— a GET with no headers or extraction.static HttpSourceConfighttpSource(String url, HttpMethod method, Map<String, String> headers, Optional<ExtractSpec> extract, Optional<PaginateSpec> paginate, List<ColumnSpec> columns, Optional<String> body, Optional<AuthSpec> auth) from http { … }, fully specified.static ImportStatementimport "<path>"— a bulk import of everything the script declares.static ImportStatementimportNames(ImportKind kind, List<String> names, String sourcePath) A named import, e.g.static JsonFileSourceConfigjsonSource(String path) from json { … }reading the whole document.static JsonFileSourceConfigjsonSource(String path, Optional<String> records) from json { … }reading a records path.static JsonFileSourceConfigjsonSource(String path, Optional<String> records, List<ColumnReference> references) from json { …, references: { … } }.static MarkdownInlineTableA markdown inline table — the pipe-delimited literal form.static ParameterDefinitionparam(String name, ScalarType type) A function parameter,name: type.static QueryStatementquery { <expression> };— a query over an anonymous expression.static QueryStatementquery { <Name> };— a query naming an already-bound relation.static ColumnReferenceThe single-column form ofreference(List, String, List).static ColumnReferenceA foreign-key edge for a source'sreferences:block,cols -> Target.cols— one edge of the schema graph a script declares.static RelateStatementrelate(String name, EndpointSpec source, EndpointSpec target) relate <name> …— one directed relationship edge of the schema graph.static RelateStatementrelate(String name, Optional<String> inverseName, boolean symmetric, EndpointSpec source, EndpointSpec target) relate, with an inverse name and/or symmetry.static ParameterDefinitionrelationParam(String name, ColumnDefinition... columns) A relation parameter —name: RELATION(columns…)— for a table-valueddef.static ScriptA script in the default namespace.static ScriptA script declaringnamespace <name>;.static SourceDeclarationsource(boolean exported, String name, SourceConfig config) source, exported or not.static SourceDeclarationsource(String name, SourceConfig config) source <name> from <config>.static StructTypestruct(StructType.Field... fields) A struct type over the given fields.Methods inherited from class com.darkcollective.relix.ast.AstBuilders
agg, agg, aggOf, allocation, and, antiJoin, argAgg, argAgg, arith, arrayOf, asc, asOfJoin, asOfJoin, attr, attrs, bool, closure, closure, closure, closure, cluster, cmp, cols, composition, condition, constraint, cover, cover, date, desc, difference, distinct, division, downsample, downsample, downsample, downsample, duration, elementOf, emptyOf, emptyRel, field, fixpoint, fullJoin, func, groupBy, groupByKeys, intersection, intervalJoin, iterate, join, key, key, lateral, leftJoin, like, limit, limit, naturalJoin, not, notElementOf, notLike, nullPred, num, optimize, optimize, or, outerUnion, pairwiseUniversal, path, path, path, pivot, produceBound, product, project, projected, projected, recRef, rel, rel, rename, rename, renamePair, reservoirSample, reservoirSample, rightJoin, rounds, sample, sample, select, semiJoin, sessionize, sessionize, set, solve, sort, sortKey, str, structOf, symmetricDifference, time, timestamp, topK, topK, trace, trace, trace, tree, tree, tvf, unary, union, unionAll, unitRel, universal, unnest, unnest, unnest, unpivot, untilConverged, untilStable, why, window
-
Constructor Details
-
ScriptBuilders
public ScriptBuilders()
-
-
Method Details
-
script
A script in the default namespace. -
script
A script declaringnamespace <name>;. -
env
envwith the default file and no active environment. -
env
env "<file>" [as <name>]. -
importAll
import "<path>"— a bulk import of everything the script declares. -
importNames
A named import, e.g.import relation Orders from "orders.relix". -
connection
public static ConnectionDeclaration connection(String name, String connectorType, Map<String, String> properties) connection <name> from <type> { … }. -
connection
connection <name> from jdbc { url: … }— the JDBC shorthand the record itself offers, exported. -
connection
public static ConnectionDeclaration connection(boolean exported, String name, String connectorType, Map<String, String> properties) connection, exported or not. -
source
source <name> from <config>. -
source
source, exported or not. -
relate
relate <name> …— one directed relationship edge of the schema graph. -
relate
public static RelateStatement relate(String name, Optional<String> inverseName, boolean symmetric, EndpointSpec source, EndpointSpec target) relate, with an inverse name and/or symmetry. -
endpoint
An endpoint of arelate, with the default[0..*]bounds. -
endpoint
public static EndpointSpec endpoint(String relationRef, List<String> columns, long min, OptionalLong max) An endpoint with explicit cardinality bounds. -
assign
Name := { <expression> };— a view binding. -
assign
A view binding, exported or not. -
assign
Name := [ … ];— an inline-table binding. -
assign
An inline-table binding, exported or not. -
def
public static DefStatement def(String name, List<ParameterDefinition> parameters, ScalarType returnType, Operand body) def <name>(…): <type> = <operand>— a scalar function. -
def
public static DefStatement def(boolean exported, String name, List<ParameterDefinition> parameters, ScalarType returnType, Operand body) A scalardef, exported or not. -
defRelation
public static DefRelationStatement defRelation(String name, List<ParameterDefinition> parameters, RelNode body) def relation <name>(…) = { … }— a table-valued function. -
defRelation
public static DefRelationStatement defRelation(boolean exported, String name, List<ParameterDefinition> parameters, RelNode body) A relationdef, exported or not. -
query
query { <Name> };— a query naming an already-bound relation. -
query
query { <expression> };— a query over an anonymous expression. -
param
A function parameter,name: type. -
relationParam
A relation parameter —name: RELATION(columns…)— for a table-valueddef. -
column
An output column of a source schema. -
column
An output column of a nested type — a struct, or an array of anything.Separate from the
ScalarTypeoverload rather than replacing it, so the common case still readscolumn("id", ScalarType.NUMBER)without a cast. -
field
A struct field, for building a nested column type. -
struct
A struct type over the given fields. -
array
An array type overelement. -
column
An output column bound to an extraction path. -
markdownTable
A markdown inline table — the pipe-delimited literal form. -
csvTable
A CSV inline table. -
csvSource
from csv { … }with a header row. -
csvSource
public static CsvFileSourceConfig csvSource(String path, boolean hasHeader, List<ColumnSpec> columns) from csv { … }, header row optional. -
jsonSource
from json { … }reading the whole document. -
jsonSource
from json { … }reading a records path. -
databaseSource
from database { url: …, table: … }. -
connectionTable
public static ConnectionTableSourceConfig connectionTable(String connection, String table, ColumnSpec... columns) from <connection>.<table>. -
reference
public static ColumnReference reference(List<String> sourceColumns, String targetRelation, List<String> targetColumns) A foreign-key edge for a source'sreferences:block,cols -> Target.cols— one edge of the schema graph a script declares.- Parameters:
sourceColumns- this source's columns; never emptytargetRelation- the relation the edge points attargetColumns- the target's columns, paired withsourceColumns- Returns:
- the reference
-
reference
public static ColumnReference reference(String sourceColumn, String targetRelation, String targetColumn) The single-column form ofreference(List, String, List). -
csvSource
public static CsvFileSourceConfig csvSource(String path, boolean hasHeader, List<ColumnSpec> columns, List<ColumnReference> references) from csv { …, references: { … } }.The three configurations that can carry a
references:block each take one, so the schema graph a script declares is expressible from here. Without them the component existed on the record and on no factory, which is how it came to be dropped by the printer with a full round-trip corpus in place. -
databaseSource
public static DatabaseSourceConfig databaseSource(String url, String table, List<ColumnSpec> columns, List<ColumnReference> references) from database { …, references: { … } }. -
connectionTable
public static ConnectionTableSourceConfig connectionTable(String connection, String table, List<ColumnSpec> columns, List<ColumnReference> references) from <connection>.<table> { references: { … } }. -
jsonSource
public static JsonFileSourceConfig jsonSource(String path, Optional<String> records, List<ColumnReference> references) from json { …, references: { … } }. -
httpSource
from http { … }— a GET with no headers or extraction. -
httpSource
public static HttpSourceConfig httpSource(String url, HttpMethod method, Map<String, String> headers, Optional<ExtractSpec> extract, Optional<PaginateSpec> paginate, List<ColumnSpec> columns, Optional<String> body, Optional<AuthSpec> auth) from http { … }, fully specified. -
generatorSource
from generator <name> { … }.
-