diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-mysql/src/main/antlr4/imports/mysql/BaseRule.g4 b/sharding-core/sharding-core-parse/sharding-core-parse-mysql/src/main/antlr4/imports/mysql/BaseRule.g4 index 1b11ae4c2881c..6dbb2f39dac4c 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-mysql/src/main/antlr4/imports/mysql/BaseRule.g4 +++ b/sharding-core/sharding-core-parse/sharding-core-parse-mysql/src/main/antlr4/imports/mysql/BaseRule.g4 @@ -67,7 +67,7 @@ characterSetName_ ; collateName_ - : IDENTIFIER_ + : COLLATE IDENTIFIER_ ; identifier_ diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-mysql/src/main/antlr4/imports/mysql/DDLStatement.g4 b/sharding-core/sharding-core-parse/sharding-core-parse-mysql/src/main/antlr4/imports/mysql/DDLStatement.g4 index ddd52bdafe1ec..bff5089bc55c2 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-mysql/src/main/antlr4/imports/mysql/DDLStatement.g4 +++ b/sharding-core/sharding-core-parse/sharding-core-parse-mysql/src/main/antlr4/imports/mysql/DDLStatement.g4 @@ -20,7 +20,39 @@ grammar DDLStatement; import Symbol, Keyword, Literals, BaseRule; createTable - : CREATE TEMPORARY? TABLE (IF NOT EXISTS)? tableName (LP_ createDefinitions_ RP_ | createLike_) + : CREATE createSpecification_ TABLE notExistClause_ tableName (createDefinitionClause_ | createLikeClause_) + ; + +createIndex + : CREATE (UNIQUE | FULLTEXT | SPATIAL)? INDEX indexName indexType_? ON tableName + ; + +alterTable + : ALTER TABLE tableName alterSpecifications_? + ; + +dropTable + : DROP TEMPORARY? TABLE (IF EXISTS)? tableName (COMMA_ tableName)* + ; + +dropIndex + : DROP INDEX (ONLINE | OFFLINE)? indexName ON tableName + ; + +truncateTable + : TRUNCATE TABLE? tableName + ; + +createSpecification_ + : TEMPORARY? + ; + +notExistClause_ + : (IF NOT EXISTS)? + ; + +createDefinitionClause_ + : LP_ createDefinitions_ RP_ ; createDefinitions_ @@ -43,14 +75,12 @@ inlineDataType_ | STORAGE (DISK | MEMORY | DEFAULT) ; -generatedDataType_ - : commonDataTypeOption_ - | (GENERATED ALWAYS)? AS expr - | (VIRTUAL | STORED) +commonDataTypeOption_ + : primaryKey | UNIQUE KEY? | NOT? NULL | collateName_ | checkConstraintDefinition_ | referenceDefinition_ | COMMENT STRING_ ; -commonDataTypeOption_ - : primaryKey | UNIQUE KEY? | NOT? NULL | collateClause_ | checkConstraintDefinition_ | referenceDefinition_ | COMMENT STRING_ +checkConstraintDefinition_ + : (CONSTRAINT ignoredIdentifier_?)? CHECK expr (NOT? ENFORCED)? ; referenceDefinition_ @@ -61,6 +91,12 @@ referenceOption_ : RESTRICT | CASCADE | SET NULL | NO ACTION | SET DEFAULT ; +generatedDataType_ + : commonDataTypeOption_ + | (GENERATED ALWAYS)? AS expr + | (VIRTUAL | STORED) + ; + indexDefinition_ : (FULLTEXT | SPATIAL)? (INDEX | KEY)? indexName? indexType_? keyParts_ indexOption_* ; @@ -101,16 +137,8 @@ foreignKeyOption_ : FOREIGN KEY indexName? columnNames referenceDefinition_ ; -checkConstraintDefinition_ - : (CONSTRAINT ignoredIdentifier_?)? CHECK expr (NOT? ENFORCED)? - ; - -createLike_ - : LIKE tableName | LP_ LIKE tableName RP_ - ; - -alterTable - : ALTER TABLE tableName alterSpecifications_? +createLikeClause_ + : LP_? LIKE tableName RP_? ; alterSpecifications_ @@ -280,19 +308,3 @@ partitionDefinitionOption_ subpartitionDefinition_ : SUBPARTITION identifier_ partitionDefinitionOption_* ; - -dropTable - : DROP TEMPORARY? TABLE (IF EXISTS)? tableName (COMMA_ tableName)* - ; - -truncateTable - : TRUNCATE TABLE? tableName - ; - -createIndex - : CREATE (UNIQUE | FULLTEXT | SPATIAL)? INDEX indexName indexType_? ON tableName - ; - -dropIndex - : DROP INDEX (ONLINE | OFFLINE)? indexName ON tableName - ; diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-oracle/src/main/antlr4/imports/oracle/DDLStatement.g4 b/sharding-core/sharding-core-parse/sharding-core-parse-oracle/src/main/antlr4/imports/oracle/DDLStatement.g4 index 106773f721b4d..0c0e52385868c 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-oracle/src/main/antlr4/imports/oracle/DDLStatement.g4 +++ b/sharding-core/sharding-core-parse/sharding-core-parse-oracle/src/main/antlr4/imports/oracle/DDLStatement.g4 @@ -20,21 +20,38 @@ grammar DDLStatement; import Symbol, Keyword, Literals, BaseRule; createTable - : CREATE (GLOBAL TEMPORARY)? TABLE tableName relationalTable + : CREATE createSpecification_ TABLE tableName createDefinitionClause_ + ; + +createIndex + : CREATE (UNIQUE | BITMAP)? INDEX indexName ON (tableIndexClause_ | bitmapJoinIndexClause_) ; alterTable : ALTER TABLE tableName (alterTableProperties | columnClauses | constraintClauses | alterExternalTable)? ; +// TODO hongjun throw exeption when alter index on oracle +alterIndex + : ALTER INDEX indexName (RENAME TO indexName)? + ; + dropTable : DROP TABLE tableName ; + +dropIndex + : DROP INDEX indexName + ; truncateTable : TRUNCATE TABLE tableName ; +createSpecification_ + : (GLOBAL TEMPORARY)? + ; + tablespaceClauseWithParen : LP_ tablespaceClause RP_ ; @@ -47,8 +64,8 @@ domainIndexClause : indexTypeName ; -relationalTable - : (LP_ relationalProperties RP_)? (ON COMMIT (DELETE | PRESERVE) ROWS)? tableProperties +createDefinitionClause_ + : (LP_ relationalProperties RP_)? (ON COMMIT (DELETE | PRESERVE) ROWS)? ; relationalProperties @@ -59,6 +76,90 @@ relationalProperty : columnDefinition | virtualColumnDefinition | outOfLineConstraint | outOfLineRefConstraint ; +columnDefinition + : columnName dataType SORT? (VISIBLE | INVISIBLE)? (DEFAULT (ON NULL)? expr | identityClause)? (ENCRYPT encryptionSpecification_)? (inlineConstraint+ | inlineRefConstraint)? + ; + +identityClause + : GENERATED (ALWAYS | BY DEFAULT (ON NULL)?) AS IDENTITY LP_? (identityOptions+)? RP_? + ; + +identityOptions + : START WITH (NUMBER_ | LIMIT VALUE) + | INCREMENT BY NUMBER_ + | MAXVALUE NUMBER_ + | NOMAXVALUE + | MINVALUE NUMBER_ + | NOMINVALUE + | CYCLE + | NOCYCLE + | CACHE NUMBER_ + | NOCACHE + | ORDER + | NOORDER + ; + +encryptionSpecification_ + : (USING STRING_)? (IDENTIFIED BY STRING_)? STRING_? (NO? SALT)? + ; + +inlineConstraint + : (CONSTRAINT ignoredIdentifier_)? (NOT? NULL | UNIQUE | primaryKey | referencesClause | CHECK LP_ expr RP_) constraintState* + ; + +referencesClause + : REFERENCES tableName columnNames? (ON DELETE (CASCADE | SET NULL))? + ; + +constraintState + : notDeferrable + | initiallyClause + | RELY | NORELY + | usingIndexClause + | ENABLE | DISABLE + | VALIDATE | NOVALIDATE + | exceptionsClause + ; + +notDeferrable + : NOT? DEFERRABLE + ; + +initiallyClause + : INITIALLY (IMMEDIATE | DEFERRED) + ; + +exceptionsClause + : EXCEPTIONS INTO tableName + ; + +usingIndexClause + : USING INDEX (indexName | LP_ createIndex RP_)? + ; + +inlineRefConstraint + : SCOPE IS tableName | WITH ROWID | (CONSTRAINT ignoredIdentifier_)? referencesClause constraintState* + ; + +virtualColumnDefinition + : columnName dataType? (GENERATED ALWAYS)? AS LP_ expr RP_ VIRTUAL? inlineConstraint* + ; + +outOfLineConstraint + : (CONSTRAINT ignoredIdentifier_)? + (UNIQUE columnNames + | primaryKey columnNames + | FOREIGN KEY columnNames referencesClause + | CHECK LP_ expr RP_ + ) constraintState* + ; + +outOfLineRefConstraint + : SCOPE FOR LP_ lobItem RP_ IS tableName + | REF LP_ lobItem RP_ WITH ROWID + | (CONSTRAINT ignoredIdentifier_)? FOREIGN KEY lobItemList referencesClause constraintState* + ; + tableProperties : columnProperties? (AS unionSelect)? ; @@ -68,7 +169,7 @@ unionSelect ; alterTableProperties - : renameTableSpecification_ | REKEY encryptionSpec + : renameTableSpecification_ | REKEY encryptionSpecification_ ; renameTableSpecification_ @@ -104,7 +205,7 @@ modifyColumnSpecification ; modifyColProperties - : columnName dataType? (DEFAULT expr)? (ENCRYPT encryptionSpec | DECRYPT)? inlineConstraint* + : columnName dataType? (DEFAULT expr)? (ENCRYPT encryptionSpecification_ | DECRYPT)? inlineConstraint* ; modifyColSubstitutable @@ -174,95 +275,6 @@ alterExternalTable : (addColumnSpecification | modifyColumnSpecification | dropColumnSpecification)+ ; -columnDefinition - : columnName dataType SORT? (DEFAULT (ON NULL)? expr | identityClause)? (ENCRYPT encryptionSpec)? (inlineConstraint+ | inlineRefConstraint)? - ; - -identityClause - : GENERATED (ALWAYS | BY DEFAULT (ON NULL)?) AS IDENTITY LP_? (identityOptions+)? RP_? - ; - -identityOptions - : START WITH (NUMBER_ | LIMIT VALUE) - | INCREMENT BY NUMBER_ - | MAXVALUE NUMBER_ - | NOMAXVALUE - | MINVALUE NUMBER_ - | NOMINVALUE - | CYCLE - | NOCYCLE - | CACHE NUMBER_ - | NOCACHE - | ORDER - | NOORDER - ; - -virtualColumnDefinition - : columnName dataType? (GENERATED ALWAYS)? AS LP_ expr RP_ VIRTUAL? inlineConstraint* - ; - -inlineConstraint - : (CONSTRAINT ignoredIdentifier_)? (NOT? NULL | UNIQUE | primaryKey | referencesClause | CHECK LP_ expr RP_) constraintState* - ; - -referencesClause - : REFERENCES tableName columnNames? (ON DELETE (CASCADE | SET NULL))? - ; - -constraintState - : notDeferrable - | initiallyClause - | RELY - | NORELY - | usingIndexClause - | ENABLE - | DISABLE - | VALIDATE - | NOVALIDATE - | exceptionsClause - ; - -notDeferrable - : NOT? DEFERRABLE - ; - -initiallyClause - : INITIALLY (IMMEDIATE | DEFERRED) - ; - -exceptionsClause - : EXCEPTIONS INTO - ; - -usingIndexClause - : USING INDEX (indexName | LP_ createIndex RP_)? - ; - -inlineRefConstraint - : SCOPE IS tableName | WITH ROWID | (CONSTRAINT ignoredIdentifier_)? referencesClause constraintState* - ; - -outOfLineConstraint - : (CONSTRAINT ignoredIdentifier_)? - ( - UNIQUE columnNames - | primaryKey columnNames - | FOREIGN KEY columnNames referencesClause - | CHECK LP_ expr RP_ - ) - constraintState* - ; - -outOfLineRefConstraint - : SCOPE FOR LP_ lobItem RP_ IS tableName - | REF LP_ lobItem RP_ WITH ROWID - | (CONSTRAINT ignoredIdentifier_)? FOREIGN KEY lobItemList referencesClause constraintState* - ; - -encryptionSpec - : (USING STRING_)? (IDENTIFIED BY STRING_)? STRING_? (NO? SALT)? - ; - objectProperties : objectProperty (COMMA_ objectProperty)* ; @@ -287,10 +299,6 @@ substitutableColumnClause : ELEMENT? IS OF TYPE? LP_ ONLY? dataTypeName_ RP_ | NOT? SUBSTITUTABLE AT ALL LEVELS ; -createIndex - : CREATE (UNIQUE | BITMAP)? INDEX indexName ON (tableIndexClause_ | bitmapJoinIndexClause_) - ; - tableIndexClause_ : tableName alias? LP_ indexExpr_ (COMMA_ indexExpr_)* RP_ ; @@ -307,11 +315,4 @@ columnSortClause_ : tableName alias? columnName (ASC | DESC)? ; -dropIndex - : DROP INDEX indexName - ; -// TODO hongjun throw exeption when alter index on oracle -alterIndex - : ALTER INDEX indexName (RENAME TO indexName)? - ; diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-oracle/src/main/antlr4/imports/oracle/Keyword.g4 b/sharding-core/sharding-core-parse/sharding-core-parse-oracle/src/main/antlr4/imports/oracle/Keyword.g4 index 3ccdf37f3757b..0b5f5c28310e9 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-oracle/src/main/antlr4/imports/oracle/Keyword.g4 +++ b/sharding-core/sharding-core-parse/sharding-core-parse-oracle/src/main/antlr4/imports/oracle/Keyword.g4 @@ -331,6 +331,14 @@ USER : U S E R ; +VISIBLE + : V I S I B L E + ; + +INVISIBLE + : I N V I S I B L E + ; + YEAR : Y E A R ; diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-postgresql/src/main/antlr4/imports/postgresql/BaseRule.g4 b/sharding-core/sharding-core-parse/sharding-core-parse-postgresql/src/main/antlr4/imports/postgresql/BaseRule.g4 index fa207ec4c6bd8..bb4fff44e14cd 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-postgresql/src/main/antlr4/imports/postgresql/BaseRule.g4 +++ b/sharding-core/sharding-core-parse/sharding-core-parse-postgresql/src/main/antlr4/imports/postgresql/BaseRule.g4 @@ -27,10 +27,18 @@ tableName : IDENTIFIER_ ; +tableNames + : LP_? tableName (COMMA_ tableName)* RP_? + ; + columnName : IDENTIFIER_ ; +columnNames + : LP_ columnName (COMMA_ columnName)* RP_ + ; + collationName : STRING_ | IDENTIFIER_ ; @@ -51,10 +59,6 @@ primaryKey : PRIMARY? KEY ; -columnNames - : LP_ columnName (COMMA_ columnName)* RP_ - ; - exprs : expr (COMMA_ expr)* ; @@ -222,72 +226,6 @@ asterisk : ASTERISK_ ; -columnDefinition - : columnName dataType collateClause? columnConstraint* - ; - -columnConstraint - : constraintClause? columnConstraintOption constraintOptionalParam - ; - -constraintClause - : CONSTRAINT ignoredIdentifier_ - ; - -columnConstraintOption - : NOT? NULL - | checkOption - | DEFAULT defaultExpr - | GENERATED (ALWAYS | BY DEFAULT) AS IDENTITY (LP_ sequenceOptions RP_)? - | UNIQUE indexParameters - | primaryKey indexParameters - | REFERENCES tableName (LP_ columnName RP_)? (MATCH FULL | MATCH PARTIAL | MATCH SIMPLE)?(ON DELETE action)? foreignKeyOnAction* - ; - -checkOption - : CHECK expr (NO INHERIT)? - ; - -defaultExpr - : CURRENT_TIMESTAMP | expr - ; - -sequenceOptions - : sequenceOption+ - ; - -sequenceOption - : START WITH? NUMBER_ - | INCREMENT BY? NUMBER_ - | MAXVALUE NUMBER_ - | NO MAXVALUE - | MINVALUE NUMBER_ - | NO MINVALUE - | CYCLE - | NO CYCLE - | CACHE NUMBER_ - ; - -indexParameters - : (USING INDEX TABLESPACE ignoredIdentifier_)? - ; - -action - : NO ACTION | RESTRICT | CASCADE | SET (NULL | DEFAULT) - ; - -foreignKeyOnAction - : ON (UPDATE foreignKeyOn | DELETE foreignKeyOn) - ; - -foreignKeyOn - : RESTRICT | CASCADE | SET NULL | NO ACTION | SET DEFAULT - ; - -constraintOptionalParam - : (NOT? DEFERRABLE)? (INITIALLY (DEFERRED | IMMEDIATE))? - ; - dataType : dataTypeName_ intervalFields? dataTypeLength? (WITHOUT TIME ZONE | WITH TIME ZONE)? (LBT_ RBT_)* | IDENTIFIER_ ; diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-postgresql/src/main/antlr4/imports/postgresql/DCLStatement.g4 b/sharding-core/sharding-core-parse/sharding-core-parse-postgresql/src/main/antlr4/imports/postgresql/DCLStatement.g4 index aeb8edbf58ec2..5ee012602afb1 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-postgresql/src/main/antlr4/imports/postgresql/DCLStatement.g4 +++ b/sharding-core/sharding-core-parse/sharding-core-parse-postgresql/src/main/antlr4/imports/postgresql/DCLStatement.g4 @@ -61,7 +61,7 @@ privilegeType_ ; onObjectClause_ - : TABLE? tableName (COMMA_ tableName)* + : TABLE? tableNames | DATABASE | SCHEMA | DOMAIN diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-postgresql/src/main/antlr4/imports/postgresql/DDLStatement.g4 b/sharding-core/sharding-core-parse/sharding-core-parse-postgresql/src/main/antlr4/imports/postgresql/DDLStatement.g4 index c5a0b76ad1923..242c3b6863a39 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-postgresql/src/main/antlr4/imports/postgresql/DDLStatement.g4 +++ b/sharding-core/sharding-core-parse/sharding-core-parse-postgresql/src/main/antlr4/imports/postgresql/DDLStatement.g4 @@ -19,76 +19,153 @@ grammar DDLStatement; import Symbol, Keyword, Literals, BaseRule; +createTable + : CREATE createSpecification_ TABLE notExistClause_ tableName createDefinitionClause_ inheritClause_ + ; + createIndex : CREATE UNIQUE? INDEX CONCURRENTLY? ((IF NOT EXISTS)? indexName)? ON tableName ; -dropIndex - : DROP INDEX (CONCURRENTLY)? (IF EXISTS)? indexName (COMMA_ indexName)* +alterTable + : alterTableNameWithAsterisk (alterTableActions | renameColumnSpecification | renameConstraint) | alterTableNameExists renameTableSpecification_ ; alterIndex : alterIndexName renameIndexSpecification | alterIndexDependsOnExtension | alterIndexSetTableSpace ; -createTable - : createTableHeader createDefinitions inheritClause? +dropTable + : DROP TABLE (IF EXISTS)? tableNames ; -alterTable - : alterTableNameWithAsterisk (alterTableActions | renameColumnSpecification | renameConstraint) | alterTableNameExists renameTableSpecification_ +dropIndex + : DROP INDEX (CONCURRENTLY)? (IF EXISTS)? indexName (COMMA_ indexName)* ; - + truncateTable : TRUNCATE TABLE? ONLY? tableNameParts ; -dropTable - : DROP TABLE (IF EXISTS)? tableName (COMMA_ tableName)* +createSpecification_ + : ((GLOBAL | LOCAL)? (TEMPORARY | TEMP) | UNLOGGED)? ; -alterIndexName - : ALTER INDEX (IF EXISTS)? indexName +notExistClause_ + : (IF NOT EXISTS)? ; -renameIndexSpecification - : RENAME TO indexName +createDefinitionClause_ + : LP_ (createDefinition (COMMA_ createDefinition)*)? RP_ ; -alterIndexDependsOnExtension - : ALTER INDEX indexName DEPENDS ON EXTENSION ignoredIdentifier_ +createDefinition + : columnDefinition | tableConstraint | LIKE tableName likeOption* ; -alterIndexSetTableSpace - : ALTER INDEX ALL IN TABLESPACE indexName (OWNED BY ignoredIdentifiers_)? +columnDefinition + : columnName dataType collateClause? columnConstraint* ; -tableNameParts - : tableNamePart (COMMA_ tableNamePart)* +columnConstraint + : constraintClause? columnConstraintOption constraintOptionalParam ; -tableNamePart - : tableName ASTERISK_? +constraintClause + : CONSTRAINT ignoredIdentifier_ ; -createTableHeader - : CREATE ((GLOBAL | LOCAL)? (TEMPORARY | TEMP) | UNLOGGED)? TABLE (IF NOT EXISTS)? tableName +columnConstraintOption + : NOT? NULL + | checkOption + | DEFAULT defaultExpr + | GENERATED (ALWAYS | BY DEFAULT) AS IDENTITY (LP_ sequenceOptions RP_)? + | UNIQUE indexParameters + | primaryKey indexParameters + | REFERENCES tableName columnNames? (MATCH FULL | MATCH PARTIAL | MATCH SIMPLE)? (ON (DELETE | UPDATE) action)* ; -createDefinitions - : LP_ (createDefinition (COMMA_ createDefinition)*)? RP_ +checkOption + : CHECK expr (NO INHERIT)? ; -createDefinition - : columnDefinition | tableConstraint | LIKE tableName likeOption* +defaultExpr + : CURRENT_TIMESTAMP | expr + ; + +sequenceOptions + : sequenceOption+ + ; + +sequenceOption + : START WITH? NUMBER_ + | INCREMENT BY? NUMBER_ + | MAXVALUE NUMBER_ + | NO MAXVALUE + | MINVALUE NUMBER_ + | NO MINVALUE + | CYCLE + | NO CYCLE + | CACHE NUMBER_ + | OWNED BY + ; + +indexParameters + : (USING INDEX TABLESPACE ignoredIdentifier_)? + | INCLUDE columnNames + | WITH + ; + +action + : NO ACTION | RESTRICT | CASCADE | SET (NULL | DEFAULT) + ; + +constraintOptionalParam + : (NOT? DEFERRABLE)? (INITIALLY (DEFERRED | IMMEDIATE))? ; likeOption : (INCLUDING | EXCLUDING) (COMMENTS | CONSTRAINTS | DEFAULTS | IDENTITY | INDEXES | STATISTICS | STORAGE | ALL) ; -inheritClause - : INHERITS LP_ tableName (COMMA_ tableName)* RP_ +tableConstraint + : constraintClause? tableConstraintOption constraintOptionalParam + ; + +tableConstraintOption + : checkOption + | UNIQUE columnNames indexParameters + | primaryKey columnNames indexParameters + | EXCLUDE (USING ignoredIdentifier_)? + | FOREIGN KEY columnNames REFERENCES tableName columnNames? (MATCH FULL | MATCH PARTIAL | MATCH SIMPLE)? (ON (DELETE | UPDATE) action)* + ; + +inheritClause_ + : (INHERITS tableNames)? + ; + +alterIndexName + : ALTER INDEX (IF EXISTS)? indexName + ; + +renameIndexSpecification + : RENAME TO indexName + ; + +alterIndexDependsOnExtension + : ALTER INDEX indexName DEPENDS ON EXTENSION ignoredIdentifier_ + ; + +alterIndexSetTableSpace + : ALTER INDEX ALL IN TABLESPACE indexName (OWNED BY ignoredIdentifiers_)? + ; + +tableNameParts + : tableNamePart (COMMA_ tableNamePart)* + ; + +tableNamePart + : tableName ASTERISK_? ; alterTableNameWithAsterisk @@ -205,17 +282,6 @@ usingIndexType : USING (BTREE | HASH | GIST | SPGIST | GIN | BRIN) ; -tableConstraint - : constraintClause? tableConstraintOption constraintOptionalParam - ; - -tableConstraintOption - : checkOption - | UNIQUE columnNames indexParameters - | primaryKey columnNames indexParameters - | FOREIGN KEY columnNames REFERENCES tableName columnNames (MATCH FULL | MATCH PARTIAL | MATCH SIMPLE)? foreignKeyOnAction* - ; - excludeElement : (columnName | expr) ignoredIdentifier_? (ASC | DESC)? (NULLS (FIRST | LAST))? ; diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-postgresql/src/main/antlr4/imports/postgresql/Keyword.g4 b/sharding-core/sharding-core-parse/sharding-core-parse-postgresql/src/main/antlr4/imports/postgresql/Keyword.g4 index 2040787eaef28..6ae3df689f160 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-postgresql/src/main/antlr4/imports/postgresql/Keyword.g4 +++ b/sharding-core/sharding-core-parse/sharding-core-parse-postgresql/src/main/antlr4/imports/postgresql/Keyword.g4 @@ -75,6 +75,10 @@ EXISTS : E X I S T S ; +EXCLUDE + : E X C L U D E + ; + FALSE : F A L S E ; @@ -559,6 +563,10 @@ INITIALLY : I N I T I A L L Y ; +INCLUDE + : I N C L U D E + ; + INSERT : I N S E R T ; diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-sqlserver/src/main/antlr4/imports/sqlserver/BaseRule.g4 b/sharding-core/sharding-core-parse/sharding-core-parse-sqlserver/src/main/antlr4/imports/sqlserver/BaseRule.g4 index 0e2e7facd6fea..bd9acb2c480da 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-sqlserver/src/main/antlr4/imports/sqlserver/BaseRule.g4 +++ b/sharding-core/sharding-core-parse/sharding-core-parse-sqlserver/src/main/antlr4/imports/sqlserver/BaseRule.g4 @@ -24,7 +24,7 @@ schemaName ; tableName - : IDENTIFIER_ + : (IDENTIFIER_ DOT_)? IDENTIFIER_ ; columnName diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-sqlserver/src/main/antlr4/imports/sqlserver/DDLStatement.g4 b/sharding-core/sharding-core-parse/sharding-core-parse-sqlserver/src/main/antlr4/imports/sqlserver/DDLStatement.g4 index 0d854656c52a0..d676182bb9c82 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-sqlserver/src/main/antlr4/imports/sqlserver/DDLStatement.g4 +++ b/sharding-core/sharding-core-parse/sharding-core-parse-sqlserver/src/main/antlr4/imports/sqlserver/DDLStatement.g4 @@ -19,20 +19,12 @@ grammar DDLStatement; import Symbol, Keyword, Literals, BaseRule; -createIndex - : CREATE UNIQUE? (CLUSTERED | NONCLUSTERED)? INDEX indexName ON tableName columnNames - ; - -alterIndex - : ALTER INDEX (indexName | ALL) ON tableName - ; - -dropIndex - : DROP INDEX (IF EXISTS)? indexName ON tableName +createTable + : CREATE TABLE tableName fileTableClause_ createDefinitionClause_ ; -createTable - : createTableHeader createTableBody +createIndex + : CREATE UNIQUE? (CLUSTERED | NONCLUSTERED)? INDEX indexName ON tableName columnNames ; alterTable @@ -50,80 +42,40 @@ alterTable ) ; -truncateTable - : TRUNCATE TABLE tableName +alterIndex + : ALTER INDEX (indexName | ALL) ON tableName ; dropTable : DROP TABLE (IF EXISTS)? tableName (COMMA_ tableName)* ; -createTableHeader - : CREATE TABLE tableName - ; - -createTableBody - : (AS FILETABLE)? LP_ createTableDefinition (COMMA_ createTableDefinition)* (COMMA_ periodClause)? RP_(ON (schemaName LP_ columnName RP_ | ignoredIdentifier_ | STRING_))? - (TEXTIMAGE_ON (ignoredIdentifier_ | STRING_))? ((FILESTREAM_ON (schemaName) | ignoredIdentifier_ STRING_))? (WITH LP_ tableOption (COMMA_ tableOption)* RP_)? - ; - -createTableDefinition - : columnDefinition | computedColumnDefinition | columnSetDefinition | tableConstraint | tableIndex - ; - -periodClause - : PERIOD FOR SYSTEM_TIME LP_ columnName COMMA_ columnName RP_ - ; - -tableIndex - : INDEX indexName - ( - (CLUSTERED | NONCLUSTERED)? columnNames - | CLUSTERED COLUMNSTORE - | NONCLUSTERED? (COLUMNSTORE columnNames | hashWithBucket) - | CLUSTERED COLUMNSTORE (WITH LP_ COMPRESSION_DELAY EQ_ (NUMBER_ MINUTES?) RP_)? - ) - (WHERE expr)? - (WITH LP_ indexOption (COMMA_ indexOption)* RP_)? indexOnClause? - (FILESTREAM_ON (ignoredIdentifier_ | schemaName | STRING_))? - ; - -tableOption - : DATA_COMPRESSION EQ_ (NONE | ROW | PAGE) (ON PARTITIONS LP_ partitionExpressions RP_)? - | FILETABLE_DIRECTORY EQ_ ignoredIdentifier_ - | FILETABLE_COLLATE_FILENAME EQ_ (collationName | DATABASE_DEAULT) - | FILETABLE_PRIMARY_KEY_CONSTRAINT_NAME EQ_ ignoredIdentifier_ - | FILETABLE_STREAMID_UNIQUE_CONSTRAINT_NAME EQ_ ignoredIdentifier_ - | FILETABLE_FULLPATH_UNIQUE_CONSTRAINT_NAME EQ_ ignoredIdentifier_ - | SYSTEM_VERSIONING EQ_ ON (LP_ HISTORY_TABLE EQ_ tableName (COMMA_ DATA_CONSISTENCY_CHECK EQ_ (ON | OFF))? RP_)? - | REMOTE_DATA_ARCHIVE EQ_ (ON (LP_ tableStretchOptions (COMMA_ tableStretchOptions)* RP_)? | OFF LP_ MIGRATION_STATE EQ_ PAUSED RP_) - | tableOptOption - | distributionOption - | dataWareHouseTableOption +dropIndex + : DROP INDEX (IF EXISTS)? indexName ON tableName ; -tableOptOption - : (MEMORY_OPTIMIZED EQ_ ON) | (DURABILITY EQ_ (SCHEMA_ONLY | SCHEMA_AND_DATA)) | (SYSTEM_VERSIONING EQ_ ON (LP_ HISTORY_TABLE EQ_ tableName (COMMA_ DATA_CONSISTENCY_CHECK EQ_ (ON | OFF))? RP_)?) +truncateTable + : TRUNCATE TABLE tableName ; -distributionOption - : DISTRIBUTION EQ_ (HASH LP_ columnName RP_ | ROUND_ROBIN | REPLICATE) +fileTableClause_ + : (AS FILETABLE)? ; -dataWareHouseTableOption - : CLUSTERED COLUMNSTORE INDEX | HEAP | dataWareHousePartitionOption +createDefinitionClause_ + : createTableDefinitions_ partitionScheme_ fileGroup_ ; -dataWareHousePartitionOption - : (PARTITION LP_ columnName RANGE (LEFT | RIGHT)? FOR VALUES LP_ simpleExpr (COMMA_ simpleExpr)* RP_ RP_) +createTableDefinitions_ + : LP_ createTableDefinition_ (COMMA_ createTableDefinition_)* (COMMA_ periodClause)? RP_ ; -tableStretchOptions - : (FILTER_PREDICATE EQ_ (NULL | functionCall) COMMA_)? MIGRATION_STATE EQ_ (OUTBOUND | INBOUND | PAUSED) +createTableDefinition_ + : columnDefinition | computedColumnDefinition | columnSetDefinition | tableConstraint | tableIndex ; columnDefinition - : columnName dataType columnDefinitionOption* (columnConstraint(COMMA_ columnConstraint)*)? columnIndex? + : columnName dataType columnDefinitionOption* columnConstraints columnIndex? ; columnDefinitionOption @@ -154,30 +106,6 @@ diskTablePrimaryKeyConstraintOption : (CLUSTERED | NONCLUSTERED)? primaryKeyWithClause? primaryKeyOnClause? ; -columnForeignKeyConstraint - : (FOREIGN KEY)? REFERENCES tableName LP_ columnName RP_ foreignKeyOnAction* - ; - -foreignKeyOnAction - : ON (DELETE | UPDATE) foreignKeyOn | NOT FOR REPLICATION - ; - -foreignKeyOn - : NO ACTION | CASCADE | SET (NULL | DEFAULT) - ; - -memoryTablePrimaryKeyConstraintOption - : CLUSTERED withBucket? - ; - -hashWithBucket - : HASH columnNames withBucket - ; - -withBucket - : WITH LP_ BUCKET_COUNT EQ_ NUMBER_ RP_ - ; - primaryKeyWithClause : WITH (FILLFACTOR EQ_ NUMBER_ | LP_ indexOption (COMMA_ indexOption)* RP_) ; @@ -198,6 +126,26 @@ onString : ON STRING_ ; +memoryTablePrimaryKeyConstraintOption + : CLUSTERED withBucket? + ; + +withBucket + : WITH LP_ BUCKET_COUNT EQ_ NUMBER_ RP_ + ; + +columnForeignKeyConstraint + : (FOREIGN KEY)? REFERENCES tableName LP_ columnName RP_ foreignKeyOnAction* + ; + +foreignKeyOnAction + : ON (DELETE | UPDATE) foreignKeyOn | NOT FOR REPLICATION + ; + +foreignKeyOn + : NO ACTION | CASCADE | SET (NULL | DEFAULT) + ; + checkConstraint : CHECK(NOT FOR REPLICATION)? LP_ expr RP_ ; @@ -214,6 +162,18 @@ onDefault : ON DEFAULT ; +columnConstraints + : (columnConstraint(COMMA_ columnConstraint)*)? + ; + +computedColumnDefinition + : columnName AS expr (PERSISTED(NOT NULL)?)? columnConstraint? + ; + +columnSetDefinition + : ignoredIdentifier_ IDENTIFIER_ COLUMN_SET FOR ALL_SPARSE_COLUMNS + ; + tableConstraint : (CONSTRAINT ignoredIdentifier_)? (tablePrimaryConstraint | tableForeignKeyConstraint | checkConstraint) ; @@ -234,16 +194,69 @@ memoryTablePrimaryConstraintOption : NONCLUSTERED (columnNames | hashWithBucket) ; +hashWithBucket + : HASH columnNames withBucket + ; + tableForeignKeyConstraint : (FOREIGN KEY)? columnNames REFERENCES tableName columnNames foreignKeyOnAction* ; -computedColumnDefinition - : columnName AS expr (PERSISTED(NOT NULL)?)? columnConstraint? +tableIndex + : INDEX indexName + ((CLUSTERED | NONCLUSTERED)? columnNames + | CLUSTERED COLUMNSTORE + | NONCLUSTERED? (COLUMNSTORE columnNames | hashWithBucket) + | CLUSTERED COLUMNSTORE (WITH LP_ COMPRESSION_DELAY EQ_ (NUMBER_ MINUTES?) RP_)?) + (WHERE expr)? + (WITH LP_ indexOption (COMMA_ indexOption)* RP_)? indexOnClause? + (FILESTREAM_ON (ignoredIdentifier_ | schemaName | STRING_))? ; -columnSetDefinition - : ignoredIdentifier_ IDENTIFIER_ COLUMN_SET FOR ALL_SPARSE_COLUMNS +tableOption + : DATA_COMPRESSION EQ_ (NONE | ROW | PAGE) (ON PARTITIONS LP_ partitionExpressions RP_)? + | FILETABLE_DIRECTORY EQ_ ignoredIdentifier_ + | FILETABLE_COLLATE_FILENAME EQ_ (collationName | DATABASE_DEAULT) + | FILETABLE_PRIMARY_KEY_CONSTRAINT_NAME EQ_ ignoredIdentifier_ + | FILETABLE_STREAMID_UNIQUE_CONSTRAINT_NAME EQ_ ignoredIdentifier_ + | FILETABLE_FULLPATH_UNIQUE_CONSTRAINT_NAME EQ_ ignoredIdentifier_ + | SYSTEM_VERSIONING EQ_ ON (LP_ HISTORY_TABLE EQ_ tableName (COMMA_ DATA_CONSISTENCY_CHECK EQ_ (ON | OFF))? RP_)? + | REMOTE_DATA_ARCHIVE EQ_ (ON (LP_ tableStretchOptions (COMMA_ tableStretchOptions)* RP_)? | OFF LP_ MIGRATION_STATE EQ_ PAUSED RP_) + | tableOptOption + | distributionOption + | dataWareHouseTableOption + ; + +tableOptOption + : (MEMORY_OPTIMIZED EQ_ ON) | (DURABILITY EQ_ (SCHEMA_ONLY | SCHEMA_AND_DATA)) | (SYSTEM_VERSIONING EQ_ ON (LP_ HISTORY_TABLE EQ_ tableName (COMMA_ DATA_CONSISTENCY_CHECK EQ_ (ON | OFF))? RP_)?) + ; + +distributionOption + : DISTRIBUTION EQ_ (HASH LP_ columnName RP_ | ROUND_ROBIN | REPLICATE) + ; + +dataWareHouseTableOption + : CLUSTERED COLUMNSTORE INDEX | HEAP | dataWareHousePartitionOption + ; + +dataWareHousePartitionOption + : (PARTITION LP_ columnName RANGE (LEFT | RIGHT)? FOR VALUES LP_ simpleExpr (COMMA_ simpleExpr)* RP_ RP_) + ; + +tableStretchOptions + : (FILTER_PREDICATE EQ_ (NULL | functionCall) COMMA_)? MIGRATION_STATE EQ_ (OUTBOUND | INBOUND | PAUSED) + ; + +partitionScheme_ + : (ON (schemaName LP_ columnName RP_ | ignoredIdentifier_ | STRING_))? + ; + +fileGroup_ + : (TEXTIMAGE_ON (ignoredIdentifier_ | STRING_))? ((FILESTREAM_ON (schemaName) | ignoredIdentifier_ STRING_))? (WITH LP_ tableOption (COMMA_ tableOption)* RP_)? + ; + +periodClause + : PERIOD FOR SYSTEM_TIME LP_ columnName COMMA_ columnName RP_ ; alterTableOp