Skip to content

Commit

Permalink
Merge pull request #2280 from tristaZero/dev
Browse files Browse the repository at this point in the history
Review the parsing rule for DDL
  • Loading branch information
terrymanu authored Apr 26, 2019
2 parents ce1cde3 + 4ca79a5 commit 9061ef2
Show file tree
Hide file tree
Showing 10 changed files with 392 additions and 346 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ characterSetName_
;

collateName_
: IDENTIFIER_
: COLLATE IDENTIFIER_
;

identifier_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_
Expand All @@ -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_
Expand All @@ -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_*
;
Expand Down Expand Up @@ -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_
Expand Down Expand Up @@ -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
;
Original file line number Diff line number Diff line change
Expand Up @@ -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_
;
Expand All @@ -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
Expand All @@ -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)?
;
Expand All @@ -68,7 +169,7 @@ unionSelect
;

alterTableProperties
: renameTableSpecification_ | REKEY encryptionSpec
: renameTableSpecification_ | REKEY encryptionSpecification_
;

renameTableSpecification_
Expand Down Expand Up @@ -104,7 +205,7 @@ modifyColumnSpecification
;

modifyColProperties
: columnName dataType? (DEFAULT expr)? (ENCRYPT encryptionSpec | DECRYPT)? inlineConstraint*
: columnName dataType? (DEFAULT expr)? (ENCRYPT encryptionSpecification_ | DECRYPT)? inlineConstraint*
;

modifyColSubstitutable
Expand Down Expand Up @@ -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)*
;
Expand All @@ -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_
;
Expand All @@ -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)?
;
Loading

0 comments on commit 9061ef2

Please sign in to comment.