Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review the parsing rule for DDL #2280

Merged
merged 34 commits into from
Apr 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
dd65fa4
adjust the sequences of statements for mysql
tristaZero Apr 24, 2019
ac15787
adjust the sequences of statements for oracle
tristaZero Apr 24, 2019
7830568
adjust the sequences of statements for pg
tristaZero Apr 24, 2019
bfc25cd
adjust the sequences of statements for sqlserver
tristaZero Apr 24, 2019
47bba02
add existClause_
tristaZero Apr 25, 2019
9014d92
modify collateName_
tristaZero Apr 25, 2019
0eb83d9
modify commonDataTypeOption_
tristaZero Apr 25, 2019
5925cab
use collateName_
tristaZero Apr 25, 2019
11d343d
add VISIBLE
tristaZero Apr 25, 2019
5f9cbe3
add temporaryClause_
tristaZero Apr 25, 2019
05f1cc3
modify constraintState
tristaZero Apr 25, 2019
0413f93
Merge branch 'dev' of ssh://github.com/shardingjdbc/sharding-jdbc int…
tristaZero Apr 26, 2019
215f4c4
add key words
tristaZero Apr 26, 2019
c0fb2f2
modify rule for creating table
tristaZero Apr 26, 2019
1c3ec57
modify basic rule
tristaZero Apr 26, 2019
dfe2d24
move columnDefinition
tristaZero Apr 26, 2019
6429999
modify createTable rule
tristaZero Apr 26, 2019
18d7325
add tableNames rule
tristaZero Apr 26, 2019
7138ec8
use tableNames
tristaZero Apr 26, 2019
cad3eff
adjust sequence of rules
tristaZero Apr 26, 2019
bdfbe1a
modify tableName rule
tristaZero Apr 26, 2019
39765ba
modify createTable rule
tristaZero Apr 26, 2019
f4ab0dd
modify columnConstraints rule
tristaZero Apr 26, 2019
ea72d69
change sequences of rules
tristaZero Apr 26, 2019
0f1e66f
rename to createDefinitionClause_
tristaZero Apr 26, 2019
6f4a547
rename to inheritClause_
tristaZero Apr 26, 2019
ce5cd8e
modify sequence of rules
tristaZero Apr 26, 2019
10109e2
modify sequence of rules
tristaZero Apr 26, 2019
8bc9a74
Merge branch 'dev' of ssh://github.com/shardingjdbc/sharding-jdbc int…
tristaZero Apr 26, 2019
3cbeea9
rename to Specification
tristaZero Apr 26, 2019
108ee4a
rename to createSpecification_
tristaZero Apr 26, 2019
be4c86a
rename to createSpecification_
tristaZero Apr 26, 2019
2b363ee
rename to fileTableSpecification__
tristaZero Apr 26, 2019
4ca79a5
reverse to fileTableClause_
tristaZero Apr 26, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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