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 DDL Parsing rules for different databases #2292

Merged
merged 42 commits into from
Apr 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
5996409
rename to createTableSpecification_
tristaZero Apr 27, 2019
92be65e
add createIndexSpecification_
tristaZero Apr 27, 2019
fc1a850
add indexNotExistClause_
tristaZero Apr 27, 2019
be06784
rename to tableNotExistClause_
tristaZero Apr 27, 2019
297c0ff
rename to tableNotExistClause_
tristaZero Apr 27, 2019
e63e404
add createIndexSpecification_
tristaZero Apr 27, 2019
0c6c88c
add concurrentlyClause_
tristaZero Apr 27, 2019
a2ceedc
add indexExpressions_
tristaZero Apr 27, 2019
fc46ac2
modify onlyClause_
tristaZero Apr 28, 2019
dd24ba7
add tableAlias
tristaZero Apr 28, 2019
f1de2ff
modiify characterSet_
tristaZero Apr 28, 2019
d6b2c87
delete collateName_
tristaZero Apr 28, 2019
551fd33
use columnNames
tristaZero Apr 28, 2019
be3e175
check style
tristaZero Apr 28, 2019
776b27d
rename to alterClause_
tristaZero Apr 28, 2019
85c83ee
rename to addColumnSpecification
tristaZero Apr 28, 2019
c25d27c
check style
tristaZero Apr 28, 2019
6d912a0
modify alterTable
tristaZero Apr 28, 2019
d3d0fbf
modify alterClause_ rule
tristaZero Apr 28, 2019
646900c
modify alterTable rule
tristaZero Apr 28, 2019
b6c7fc0
rename to generatedColumnNameClause
tristaZero Apr 28, 2019
5369356
add generatedColumnNamesClause
tristaZero Apr 28, 2019
f97d1e0
modify alterClause_ rule
tristaZero Apr 28, 2019
1368268
modify dropTable rule
tristaZero Apr 28, 2019
12e2843
add tableNames
tristaZero Apr 28, 2019
d0d92e9
modify dropIndex rule
tristaZero Apr 28, 2019
8ad34bf
add createIndexDefinitionClause_
tristaZero Apr 28, 2019
e964e66
add defaultNullClause_
tristaZero Apr 28, 2019
b102b81
add createIndexClause_
tristaZero Apr 28, 2019
25b106f
modify alterIndex
tristaZero Apr 28, 2019
d64e295
add tableNamesClause
tristaZero Apr 28, 2019
e936789
rename to modifyColumn
tristaZero Apr 28, 2019
8df7263
use tableNameClause
tristaZero Apr 28, 2019
6091635
add tableNames
tristaZero Apr 28, 2019
b38e469
rename to alterDefinitionClause_
tristaZero Apr 28, 2019
8560b4b
add fileStreamOn_
tristaZero Apr 28, 2019
3d15523
modify tableIndex rule
tristaZero Apr 28, 2019
d4a4ef1
add clusterOption_
tristaZero Apr 28, 2019
69a917e
add columnExistClause_
tristaZero Apr 28, 2019
0d00ef7
add onOffOption_
tristaZero Apr 28, 2019
740a1c4
Merge branch 'dev' of ssh://github.com/shardingjdbc/sharding-jdbc int…
tristaZero Apr 28, 2019
8c39700
add blank line
tristaZero Apr 29, 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 @@ -34,7 +34,7 @@ literals
;

stringLiterals
: characterSetName_? STRING_ collateName_?
: characterSetName_? STRING_ collateClause_?
;

numberLiterals
Expand All @@ -47,11 +47,11 @@ dateTimeLiterals
;

hexadecimalLiterals
: characterSetName_? HEX_DIGIT_ collateName_?
: characterSetName_? HEX_DIGIT_ collateClause_?
;

bitValueLiterals
: characterSetName_? BIT_NUM_ collateName_?
: characterSetName_? BIT_NUM_ collateClause_?
;

booleanLiterals
Expand All @@ -66,10 +66,6 @@ characterSetName_
: IDENTIFIER_
;

collateName_
: COLLATE IDENTIFIER_
;

identifier_
: IDENTIFIER_ | unreservedWord_
;
Expand Down Expand Up @@ -112,7 +108,11 @@ columnName
;

columnNames
: LP_ columnName (COMMA_ columnName)* RP_
: LP_? columnName (COMMA_ columnName)* RP_?
;

tableNames
: LP_? tableName (COMMA_ tableName)* RP_?
;

indexName
Expand Down Expand Up @@ -355,7 +355,7 @@ dataTypeLength
;

characterSet_
: (CHARACTER | CHAR) SET EQ_? ignoredIdentifier_ | CHARSET EQ_? ignoredIdentifier_
: (CHARACTER | CHAR) SET EQ_? ignoredIdentifier_
;

collateClause_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,34 @@ grammar DDLStatement;
import Symbol, Keyword, Literals, BaseRule;

createTable
: CREATE createSpecification_ TABLE notExistClause_ tableName (createDefinitionClause_ | createLikeClause_)
: CREATE createTableSpecification_ TABLE tableNotExistClause_ tableName (createDefinitionClause_ | createLikeClause_)
;

createIndex
: CREATE (UNIQUE | FULLTEXT | SPATIAL)? INDEX indexName indexType_? ON tableName
: CREATE createIndexSpecification_ INDEX indexName indexType_? ON tableName
;

alterTable
: ALTER TABLE tableName alterSpecifications_?
: ALTER TABLE tableName alterDefinitionClause_?
;

dropTable
: DROP TEMPORARY? TABLE (IF EXISTS)? tableName (COMMA_ tableName)*
: DROP dropTableSpecification_ TABLE tableExistClause_ tableNames
;

dropIndex
: DROP INDEX (ONLINE | OFFLINE)? indexName ON tableName
: DROP INDEX dropIndexSpecification_ indexName ON tableName
;

truncateTable
: TRUNCATE TABLE? tableName
;

createSpecification_
createTableSpecification_
: TEMPORARY?
;

notExistClause_
tableNotExistClause_
: (IF NOT EXISTS)?
;

Expand Down Expand Up @@ -76,7 +76,7 @@ inlineDataType_
;

commonDataTypeOption_
: primaryKey | UNIQUE KEY? | NOT? NULL | collateName_ | checkConstraintDefinition_ | referenceDefinition_ | COMMENT STRING_
: primaryKey | UNIQUE KEY? | NOT? NULL | collateClause_ | checkConstraintDefinition_ | referenceDefinition_ | COMMENT STRING_
;

checkConstraintDefinition_
Expand Down Expand Up @@ -141,7 +141,11 @@ createLikeClause_
: LP_? LIKE tableName RP_?
;

alterSpecifications_
createIndexSpecification_
: (UNIQUE | FULLTEXT | SPATIAL)?
;

alterDefinitionClause_
: alterSpecification_ (COMMA_ alterSpecification_)*
;

Expand Down Expand Up @@ -169,7 +173,7 @@ alterSpecification_
| LOCK EQ_? (DEFAULT | NONE | SHARED | EXCLUSIVE)
| modifyColumnSpecification
// TODO hongjun investigate ORDER BY col_name [, col_name] ...
| ORDER BY columnName (COMMA_ columnName)*
| ORDER BY columnNames
| renameColumnSpecification
| renameIndexSpecification
| renameTableSpecification_
Expand Down Expand Up @@ -308,3 +312,15 @@ partitionDefinitionOption_
subpartitionDefinition_
: SUBPARTITION identifier_ partitionDefinitionOption_*
;

dropTableSpecification_
: TEMPORARY?
;

tableExistClause_
: (IF EXISTS)?
;

dropIndexSpecification_
: (ONLINE | OFFLINE)?
;
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ grammar DDLStatement;
import Symbol, Keyword, Literals, BaseRule;

createTable
: CREATE createSpecification_ TABLE tableName createDefinitionClause_
: CREATE createTableSpecification_ TABLE tableName createDefinitionClause_
;

createIndex
: CREATE (UNIQUE | BITMAP)? INDEX indexName ON (tableIndexClause_ | bitmapJoinIndexClause_)
: CREATE createIndexSpecification_ INDEX indexName ON createIndexDefinitionClause_
;

alterTable
: ALTER TABLE tableName (alterTableProperties | columnClauses | constraintClauses | alterExternalTable)?
: ALTER TABLE tableName alterDefinitionClause_
;

// TODO hongjun throw exeption when alter index on oracle
alterIndex
: ALTER INDEX indexName (RENAME TO indexName)?
: ALTER INDEX indexName renameIndexClause_
;

dropTable
Expand All @@ -48,7 +48,7 @@ truncateTable
: TRUNCATE TABLE tableName
;

createSpecification_
createTableSpecification_
: (GLOBAL TEMPORARY)?
;

Expand Down Expand Up @@ -77,14 +77,26 @@ relationalProperty
;

columnDefinition
: columnName dataType SORT? (VISIBLE | INVISIBLE)? (DEFAULT (ON NULL)? expr | identityClause)? (ENCRYPT encryptionSpecification_)? (inlineConstraint+ | inlineRefConstraint)?
: columnName dataType SORT? visibleClause_ (defaultNullClause_ expr | identityClause)? (ENCRYPT encryptionSpecification_)? (inlineConstraint+ | inlineRefConstraint)?
;

visibleClause_
: (VISIBLE | INVISIBLE)?
;

defaultNullClause_
: DEFAULT (ON NULL)?
;

identityClause
: GENERATED (ALWAYS | BY DEFAULT (ON NULL)?) AS IDENTITY LP_? (identityOptions+)? RP_?
: GENERATED (ALWAYS | BY DEFAULT (ON NULL)?) AS IDENTITY identifyOptions
;

identityOptions
identifyOptions
: LP_? (identityOption+)? RP_?
;

identityOption
: START WITH (NUMBER_ | LIMIT VALUE)
| INCREMENT BY NUMBER_
| MAXVALUE NUMBER_
Expand Down Expand Up @@ -134,7 +146,11 @@ exceptionsClause
;

usingIndexClause
: USING INDEX (indexName | LP_ createIndex RP_)?
: USING INDEX (indexName | createIndexClause_)?
;

createIndexClause_
: LP_ createIndex RP_
;

inlineRefConstraint
Expand All @@ -160,12 +176,44 @@ outOfLineRefConstraint
| (CONSTRAINT ignoredIdentifier_)? FOREIGN KEY lobItemList referencesClause constraintState*
;

tableProperties
: columnProperties? (AS unionSelect)?
createIndexSpecification_
: (UNIQUE | BITMAP)?
;

tableIndexClause_
: tableName alias? indexExpressions_
;

indexExpressions_
: LP_ indexExpression_ (COMMA_ indexExpression_)* RP_
;

indexExpression_
: (columnName | expr) (ASC | DESC)?
;

bitmapJoinIndexClause_
: tableName columnSortsClause_ FROM tableAlias WHERE expr
;

columnSortsClause_
: LP_ columnSortClause_ (COMMA_ columnSortClause_)* RP_
;

columnSortClause_
: (tableName | alias)? columnName (ASC | DESC)?
;

createIndexDefinitionClause_
: tableIndexClause_ | bitmapJoinIndexClause_
;

tableAlias
: tableName alias? (COMMA_ tableName alias?)*
;

unionSelect
: matchNone
alterDefinitionClause_
: (alterTableProperties | columnClauses | constraintClauses | alterExternalTable)?
;

alterTableProperties
Expand All @@ -181,10 +229,10 @@ newTableName
;

columnClauses
: opColumnClause+ | renameColumnSpecification
: operateColumnClause+ | renameColumnClause
;

opColumnClause
operateColumnClause
: addColumnSpecification | modifyColumnSpecification | dropColumnClause
;

Expand All @@ -200,6 +248,22 @@ columnOrVirtualDefinition
: columnDefinition | virtualColumnDefinition
;

columnProperties
: columnProperty+
;

columnProperty
: objectTypeColProperties
;

objectTypeColProperties
: COLUMN columnName substitutableColumnClause
;

substitutableColumnClause
: ELEMENT? IS OF TYPE? LP_ ONLY? dataTypeName_ RP_ | NOT? SUBSTITUTABLE AT ALL LEVELS
;

modifyColumnSpecification
: MODIFY (LP_? modifyColProperties (COMMA_ modifyColProperties)* RP_? | modifyColSubstitutable)
;
Expand Down Expand Up @@ -232,7 +296,7 @@ checkpointNumber
: CHECKPOINT NUMBER_
;

renameColumnSpecification
renameColumnClause
: RENAME COLUMN columnName TO columnName
;

Expand Down Expand Up @@ -283,36 +347,6 @@ objectProperty
: (columnName | attributeName) (DEFAULT expr)? (inlineConstraint* | inlineRefConstraint?) | outOfLineConstraint | outOfLineRefConstraint
;

columnProperties
: columnProperty+
;

columnProperty
: objectTypeColProperties
renameIndexClause_
: (RENAME TO indexName)?
;

objectTypeColProperties
: COLUMN columnName substitutableColumnClause
;

substitutableColumnClause
: ELEMENT? IS OF TYPE? LP_ ONLY? dataTypeName_ RP_ | NOT? SUBSTITUTABLE AT ALL LEVELS
;

tableIndexClause_
: tableName alias? LP_ indexExpr_ (COMMA_ indexExpr_)* RP_
;

indexExpr_
: (columnName | expr) (ASC | DESC)?
;

bitmapJoinIndexClause_
: tableName LP_ columnSortClause_ (COMMA_ columnSortClause_)* RP_ FROM tableName alias? (COMMA_ tableName alias?)* WHERE expr
;

columnSortClause_
: tableName alias? columnName (ASC | DESC)?
;


Loading