Package dev.frostlake.executor.commands
Class ColumnDefinitionParser
java.lang.Object
dev.frostlake.executor.commands.ColumnDefinitionParser
- All Implemented Interfaces:
CommandHandler
Parses column / data-type / constraint / default-value grammar into metastore models — extracted from
DDLCommandHandler (CREATE TABLE, CREATE FUNCTION/PROCEDURE parameters, DROP FUNCTION arg types,
ALTER) so those handlers share one parser. Implements CommandHandler only to reuse its default
getText/extractComment helpers; the parsing itself is stateless.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuildCheckConstraint(FrostlakeParser.ConstraintNameContext nameCtx, FrostlakeParser.BooleanExprContext expr, List<String> columnNames) One CHECK constraint from its parse tree: the expression kept as written, an unnamed one given the auto-generated name live reports it under, and the columns it names read from the tree.Get catalog instanceGet query executor instanceparseCheckConstraints(FrostlakeParser.ColumnListContext ctx, List<String> columnNames) Every CHECK constraint a column list declares, in declaration order — the column-level ones as their columns appear, then the table-level ones.parseDataType(FrostlakeParser.DataTypeNameContext ctx, FrostlakeParser.TypeParametersContext typeParams) A POLICY signature's parameter.The name an explicit table-levelCONSTRAINT <name> PRIMARY KEY (...)gave the key, or null when it was declared without one (or only as a column-levelPRIMARY KEY).Build a singleTableColumnfrom onecolumnDef— its data type plus column-level constraints (PRIMARY KEY, NOT NULL, UNIQUE, AUTOINCREMENT/IDENTITY, DEFAULT, column-level REFERENCES, COLLATE, COMMENT).parseSingleColumnDef(FrostlakeParser.ColumnDefContext colDef, boolean addColumn) As above, withaddColumntelling which surface asked.The table-level UNIQUE constraints of a column list — ONE per declaration, soUNIQUE (a, b)is a single multi-column constraint rather than one constraint per column.static voidrejectDuplicateNames(List<String> names) The same rule over bare NAMES, for the lists that carry no types — a CTAS's names-only list and a view's column list, both of which live refuses with this same sentence.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface dev.frostlake.executor.commands.CommandHandler
extractComment, extractComment, getText, getText, qualifiedNameParts
-
Constructor Details
-
ColumnDefinitionParser
-
-
Method Details
-
getCatalog
Description copied from interface:CommandHandlerGet catalog instance- Specified by:
getCatalogin interfaceCommandHandler- Returns:
- the engine's metastore catalog, holding the objects this handler reads and mutates
-
getQueryExecutor
Description copied from interface:CommandHandlerGet query executor instance- Specified by:
getQueryExecutorin interfaceCommandHandler- Returns:
- the engine's query executor, for handlers that run nested queries or need session state
-
parseSingleColumnDef
Build a singleTableColumnfrom onecolumnDef— its data type plus column-level constraints (PRIMARY KEY, NOT NULL, UNIQUE, AUTOINCREMENT/IDENTITY, DEFAULT, column-level REFERENCES, COLLATE, COMMENT). Shared by CREATE TABLE'sparseColumnList(dev.frostlake.parser.FrostlakeParser.ColumnListContext)and ALTER TABLE ADD COLUMN, so both honour DEFAULT / NOT NULL identically. Table-level PRIMARY KEY / FOREIGN KEY constraints are the caller's concern, not this method's. -
parseSingleColumnDef
As above, withaddColumntelling which surface asked. It matters for DEFAULTs: CREATE TABLE judges one by COERCION (a string default is refused for the numeric and datetime families, a numeric default for VARCHAR / BOOLEAN / VARIANT, andBOOLEAN DEFAULT 'true'is taken), while ALTER TABLE ADD COLUMN judges the same default far more strictly, in the INSERT surface's own vocabulary. Only the CREATE rule is enforced here — see the ADD COLUMN task for the rest. -
rejectDuplicateNames
The same rule over bare NAMES, for the lists that carry no types — a CTAS's names-only list and a view's column list, both of which live refuses with this same sentence. -
parseColumnList
-
parsePrimaryKeyConstraintName
The name an explicit table-levelCONSTRAINT <name> PRIMARY KEY (...)gave the key, or null when it was declared without one (or only as a column-levelPRIMARY KEY). A table has at most one primary key, so the first such declaration wins. -
parseUniqueConstraints
The table-level UNIQUE constraints of a column list — ONE per declaration, soUNIQUE (a, b)is a single multi-column constraint rather than one constraint per column. Unnamed ones auto-name themselves; column-levelUNIQUEdeclarations are not returned here (they are plain column flags andTablenames them itself). -
parseCheckConstraints
public List<CheckConstraint> parseCheckConstraints(FrostlakeParser.ColumnListContext ctx, List<String> columnNames) Every CHECK constraint a column list declares, in declaration order — the column-level ones as their columns appear, then the table-level ones. GET_DDL renders them all as table-level lines whichever way they were written (live-verified), so both forms land in the same list here.- Parameters:
ctx- the parsed column listcolumnNames- the table's column names, to work out which columns each expression names
-
buildCheckConstraint
public CheckConstraint buildCheckConstraint(FrostlakeParser.ConstraintNameContext nameCtx, FrostlakeParser.BooleanExprContext expr, List<String> columnNames) One CHECK constraint from its parse tree: the expression kept as written, an unnamed one given the auto-generated name live reports it under, and the columns it names read from the tree. -
parseForeignKeys
-
parsePolicyParameterDef
A POLICY signature's parameter. Identical toparseParameterDef(dev.frostlake.parser.FrostlakeParser.ParameterDefContext)but for one measured detail: a string type declared without a length is 128MB wide here, not the column default — live reports a bare VARCHAR policy argument asVARCHAR(134217728)and an explicitly sized one as it was written. -
parseParameterDef
-
parseDataType
-
parseDataType
public DataType parseDataType(FrostlakeParser.DataTypeNameContext ctx, FrostlakeParser.TypeParametersContext typeParams) -
parseDefaultExpression
-
parseLiteral
-