From 3501c01ff949e6ef741607954daaef3857678396 Mon Sep 17 00:00:00 2001 From: niu niu Date: Mon, 23 Oct 2023 18:47:55 +0800 Subject: [PATCH] Improve alter tablespace syntax rules --- .../main/antlr4/imports/oracle/BaseRule.g4 | 8 +++ .../antlr4/imports/oracle/DDLStatement.g4 | 63 +++++++++---------- .../main/resources/case/ddl/alter-table.xml | 4 ++ .../resources/case/ddl/alter-tablespace.xml | 12 ++++ .../sql/supported/ddl/alter-table.xml | 1 + .../sql/supported/ddl/alter-tablespace.xml | 3 + 6 files changed, 56 insertions(+), 35 deletions(-) diff --git a/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/BaseRule.g4 b/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/BaseRule.g4 index 37696ef2cf32b..0fcbec7659d01 100644 --- a/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/BaseRule.g4 +++ b/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/BaseRule.g4 @@ -439,6 +439,10 @@ tablespaceName : identifier ; +newTablespaceName + : identifier + ; + subprogramName : identifier ; @@ -1727,6 +1731,10 @@ filenamePattern : STRING_ ; +replacementFilenamePattern + : STRING_ + ; + connectString : STRING_ ; diff --git a/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/DDLStatement.g4 b/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/DDLStatement.g4 index beeacb52cb438..dd2ca39561c88 100644 --- a/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/DDLStatement.g4 +++ b/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/DDLStatement.g4 @@ -3922,7 +3922,7 @@ segmentManagementClause ; tablespaceGroupClause - : TABLESPACE GROUP tablespaceGroupName + : TABLESPACE GROUP (tablespaceGroupName | SQ_ SQ_) ; temporaryTablespaceClause @@ -3957,13 +3957,14 @@ permanentTablespaceClause ; alterTablespace - : ALTER TABLESPACE tablespaceName - ( MINIMUM EXTENT sizeClause + : ALTER TABLESPACE tablespaceName + ( defaultTablespaceParams + | MINIMUM EXTENT sizeClause | RESIZE sizeClause | COALESCE | SHRINK SPACE (KEEP sizeClause)? | RENAME TO newTablespaceName - | (BEGIN|END) BACKUP + | (BEGIN | END) BACKUP | datafileTempfileClauses | tablespaceLoggingClauses | tablespaceGroupClause @@ -3973,53 +3974,45 @@ alterTablespace | tablespaceRetentionClause | alterTablespaceEncryption | lostWriteProtection - ) - ; + ) + ; -newTablespaceName - : identifier - ; +defaultTablespaceParams + : DEFAULT defaultTableCompression? defaultIndexCompression? inmemoryClause? ilmClause? storageClause? + ; -datafileTempfileClauses - : ADD (datafileSpecification | tempfileSpecification) - | DROP (DATAFILE | TEMPFILE) (fileSpecification | UNSIGNED_INTEGER) (KEEP sizeClause)? - | SHRINK TEMPFILE (fileSpecification | UNSIGNED_INTEGER) (KEEP sizeClause)? - | RENAME DATAFILE fileSpecification (COMMA_ fileSpecification)* TO fileSpecification (COMMA_ fileSpecification)* - | (DATAFILE | TEMPFILE) (ONLINE|OFFLINE) - ; +defaultTableCompression + : TABLE (COMPRESS FOR OLTP | COMPRESS FOR QUERY (LOW | HIGH) | COMPRESS FOR ARCHIVE (LOW | HIGH) | NOCOMPRESS) + ; -datafileSpecification - : DATAFILE - (COMMA_? datafileTempfileSpec) - ; +defaultIndexCompression + : INDEX (COMPRESS ADVANCED (LOW | HIGH) | NOCOMPRESS) + ; -tempfileSpecification - : TEMPFILE - (COMMA_? datafileTempfileSpec) +datafileTempfileClauses + : ADD (DATAFILE | TEMPFILE) (fileSpecification (COMMA_ fileSpecification)*)? + | DROP (DATAFILE | TEMPFILE) (fileName | fileNumber) + | SHRINK TEMPFILE (fileName | fileNumber) (KEEP sizeClause)? + | RENAME DATAFILE fileName (COMMA_ fileName)* TO fileName (COMMA_ fileName)* + | (DATAFILE | TEMPFILE) (ONLINE | OFFLINE) ; tablespaceLoggingClauses - : loggingClause - | NO? FORCE LOGGING + : loggingClause | NO? FORCE LOGGING ; tablespaceStateClauses - : ONLINE - | OFFLINE (NORMAL | TEMPORARY | IMMEDIATE)? - | READ (ONLY | WRITE) - | PERMANENT - | TEMPORARY + : ONLINE | OFFLINE (NORMAL | TEMPORARY | IMMEDIATE)? | READ (ONLY | WRITE) | (PERMANENT | TEMPORARY) ; tablespaceFileNameConvert - : FILE_NAME_CONVERT EQ_ LP_ CHAR_STRING COMMA_ CHAR_STRING (COMMA_ CHAR_STRING COMMA_ CHAR_STRING)* RP_ KEEP? + : FILE_NAME_CONVERT EQ_ LP_ filenamePattern COMMA_ replacementFilenamePattern (COMMA_ filenamePattern COMMA_ replacementFilenamePattern)* RP_ KEEP? ; alterTablespaceEncryption - : ENCRYPTION ( OFFLINE (tablespaceEncryptionSpec? ENCRYPT | DECRYPT) - | ONLINE (tablespaceEncryptionSpec? (ENCRYPT | REKEY) | DECRYPT) tablespaceFileNameConvert? - | FINISH (ENCRYPT | REKEY | DECRYPT) tablespaceFileNameConvert? - ) + : ENCRYPTION(OFFLINE (tablespaceEncryptionSpec? ENCRYPT | DECRYPT) + | ONLINE (tablespaceEncryptionSpec? (ENCRYPT | REKEY) | DECRYPT) tablespaceFileNameConvert? + | FINISH (ENCRYPT | REKEY | DECRYPT) tablespaceFileNameConvert?) ; dropFunction diff --git a/test/it/parser/src/main/resources/case/ddl/alter-table.xml b/test/it/parser/src/main/resources/case/ddl/alter-table.xml index c230ad9aec0a2..1fd9f5bdae05c 100644 --- a/test/it/parser/src/main/resources/case/ddl/alter-table.xml +++ b/test/it/parser/src/main/resources/case/ddl/alter-table.xml @@ -1727,6 +1727,10 @@ + +
+ +
diff --git a/test/it/parser/src/main/resources/case/ddl/alter-tablespace.xml b/test/it/parser/src/main/resources/case/ddl/alter-tablespace.xml index 0f821a3fd69d4..7c9dccc0ec1cc 100644 --- a/test/it/parser/src/main/resources/case/ddl/alter-tablespace.xml +++ b/test/it/parser/src/main/resources/case/ddl/alter-tablespace.xml @@ -137,4 +137,16 @@ + + + + + + + + + + + + diff --git a/test/it/parser/src/main/resources/sql/supported/ddl/alter-table.xml b/test/it/parser/src/main/resources/sql/supported/ddl/alter-table.xml index 035f6877b5ee8..9e9e5cdd87098 100644 --- a/test/it/parser/src/main/resources/sql/supported/ddl/alter-table.xml +++ b/test/it/parser/src/main/resources/sql/supported/ddl/alter-table.xml @@ -235,6 +235,7 @@ + diff --git a/test/it/parser/src/main/resources/sql/supported/ddl/alter-tablespace.xml b/test/it/parser/src/main/resources/sql/supported/ddl/alter-tablespace.xml index fc7bd09906db6..395fefe68c75e 100644 --- a/test/it/parser/src/main/resources/sql/supported/ddl/alter-tablespace.xml +++ b/test/it/parser/src/main/resources/sql/supported/ddl/alter-tablespace.xml @@ -59,4 +59,7 @@ TO '/u02/oracle/rbdb1/users01.dbf', '/u02/oracle/rbdb1/users02.dbf'" db-types="Oracle" /> + + +