You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2021/05/31 06:15:49 UTC
[shardingsphere] branch master updated: complete alter table
partition grammar (#10410)
This is an automated email from the ASF dual-hosted git repository.
panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new cb6faae complete alter table partition grammar (#10410)
cb6faae is described below
commit cb6faae9c32a6bda09c93ff574e5b41dd27cdbd7
Author: Zhu jun <zh...@163.com>
AuthorDate: Mon May 31 14:15:11 2021 +0800
complete alter table partition grammar (#10410)
* add modify/move/coalesce parition grammar
* complete oracle alter table partition grammar
* fix review
* fix review
---
.../src/main/antlr4/imports/oracle/DDLStatement.g4 | 134 +++++++++++++++++++--
.../main/antlr4/imports/oracle/OracleKeyword.g4 | 16 +++
.../src/main/resources/case/ddl/alter-table.xml | 29 +++++
.../src/main/resources/sql/supported/ddl/alter.xml | 7 ++
4 files changed, 178 insertions(+), 8 deletions(-)
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/DDLStatement.g4 b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/DDLStatement.g4
index 1a656c8..4263405 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/DDLStatement.g4
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/DDLStatement.g4
@@ -964,23 +964,141 @@ alterSynonym
;
alterTablePartitioning
- : addTablePartition | dropTablePartition
+ : modifyTablePartition
+ | moveTablePartition
+ | addTablePartition
+ | coalesceTablePartition
+ | dropTablePartition
+ ;
+
+modifyTablePartition
+ : modifyRangePartition
+ | modifyHashPartition
+ | modifyListPartition
+ ;
+
+modifyRangePartition
+ : MODIFY partitionExtendedName (partitionAttributes
+ | (addRangeSubpartition | addHashSubpartition | addListSubpartition)
+ | coalesceTableSubpartition | alterMappingTableClauses | REBUILD? UNUSABLE LOCAL INDEXES
+ | readOnlyClause | indexingClause)
+ ;
+
+modifyHashPartition
+ : MODIFY partitionExtendedName (partitionAttributes | coalesceTableSubpartition
+ | alterMappingTableClauses | REBUILD? UNUSABLE LOCAL INDEXES | readOnlyClause | indexingClause)
+ ;
+
+modifyListPartition
+ : MODIFY partitionExtendedName (partitionAttributes
+ | (ADD | DROP) VALUES LP_ listValues RP_
+ | (addRangeSubpartition | addHashSubpartition | addListSubpartition)
+ | coalesceTableSubpartition | REBUILD? UNUSABLE LOCAL INDEXES | readOnlyClause | indexingClause)
+ ;
+
+partitionExtendedName
+ : PARTITION partitionName
+ | PARTITION FOR LR_ partitionKeyValue (COMMA_ partitionKeyValue)* RP_
+ ;
+
+addRangeSubpartition
+ : ADD rangeSubpartitionDesc (COMMA_ rangeSubpartitionDesc)* dependentTablesClause? updateIndexClauses?
+ ;
+
+dependentTablesClause
+ : DEPENDENT TABLES LP_ tableName LP_ partitionSpec (COMMA_ partitionSpec)* RP_
+ (COMMA_ tableName LP_ partitionSpec (COMMA_ partitionSpec)* RP_)* RP_
+ ;
+
+addHashSubpartition
+ : ADD individualHashSubparts dependentTablesClause? updateIndexClauses? parallelClause?
+ ;
+
+addListSubpartition
+ : ADD listSubpartitionDesc (COMMA_ listSubpartitionDesc)* dependentTablesClause? updateIndexClauses?
+ ;
+
+coalesceTableSubpartition
+ : COALESCE SUBPARTITION subpartitionName updateIndexClauses? parallelClause? allowDisallowClustering?
+ ;
+
+allowDisallowClustering
+ : (ALLOW | DISALLOW) CLUSTERING
+ ;
+
+alterMappingTableClauses
+ : MAPPING TABLE (allocateExtentClause | deallocateUnusedClause)
+ ;
+
+deallocateUnusedClause
+ : DEALLOCATE UNUSED (KEEP sizeClause)?
+ ;
+
+allocateExtentClause
+ : ALLOCATE EXTENT (LP_ (SIZE sizeClause | DATAFILE SQ_ fileName SQ_ | INSTANCE NUMBER_)* RP_)?
+ ;
+
+partitionSpec
+ : PARTITION partitionName? tablePartitionDescription?
+ ;
+
+partitionAttributes
+ : (physicalAttributesClause | loggingClause | allocateExtentClause | deallocateUnusedClause | shrinkClause)*
+ (OVERFLOW (physicalAttributesClause | loggingClause | allocateExtentClause | deallocateUnusedClause)*)?
+ tableCompression? inmemoryClause?
+ ;
+
+shrinkClause
+ : SHRINK SPACE COMPACT? CASCADE?
+ ;
+
+moveTablePartition
+ : MOVE partitionExtendedName (MAPPING TABLE)? tablePartitionDescription? filterCondition? updateAllIndexesClause? parallelClause? allowDisallowClustering? ONLINE?
+ ;
+
+filterCondition
+ : INCLUDING ROWS whereClause
+ ;
+
+whereClause
+ : WHERE expr
+ ;
+
+coalesceTablePartition
+ : COALESCE PARTITION updateIndexClauses? parallelClause? allowDisallowClustering?
;
addTablePartition
- : ADD (addRangePartitionClause | addListPartitionClause)
+ : ADD ((PARTITION partitionName? addRangePartitionClause (COMMA_ PARTITION partitionName? addRangePartitionClause)*)
+ | (PARTITION partitionName? addListPartitionClause (COMMA_ PARTITION partitionName? addListPartitionClause)*)
+ | (PARTITION partitionName? addSystemPartitionClause (COMMA_ PARTITION partitionName? addSystemPartitionClause)*)
+ (BEFORE (partitionName | NUMBER_))?
+ | (PARTITION partitionName? addHashPartitionClause)
+ ) dependentTablesClause?
;
addRangePartitionClause
- : PARTITION partitionName? rangeValuesClause tablePartitionDescription
- ((LP_? rangeSubpartitionDesc (COMMA_ rangeSubpartitionDesc)* | listSubpartitionDesc (COMMA_ listSubpartitionDesc)* | individualHashSubparts (COMMA_ individualHashSubparts)* RP_?)
- | hashSubpartitionQuantity)?
+ : rangeValuesClause tablePartitionDescription? externalPartSubpartDataProps?
+ ((LP_? (rangeSubpartitionDesc (COMMA_ rangeSubpartitionDesc)* | listSubpartitionDesc (COMMA_ listSubpartitionDesc)* | individualHashSubparts (COMMA_ individualHashSubparts)*) RP_?)
+ | hashSubpartsByQuantity)? updateIndexClauses?
;
addListPartitionClause
- : PARTITION partitionName? listValuesClause tablePartitionDescription
- ((LP_? rangeSubpartitionDesc (COMMA_ rangeSubpartitionDesc)* | listSubpartitionDesc (COMMA_ listSubpartitionDesc)* | individualHashSubparts (COMMA_ individualHashSubparts)* RP_?)
- | hashSubpartitionQuantity)?
+ : listValuesClause tablePartitionDescription? externalPartSubpartDataProps?
+ ((LP_? (rangeSubpartitionDesc (COMMA_ rangeSubpartitionDesc)* | listSubpartitionDesc (COMMA_ listSubpartitionDesc)* | individualHashSubparts (COMMA_ individualHashSubparts)*) RP_?)
+ | hashSubpartsByQuantity)? updateIndexClauses?
+ ;
+
+hashSubpartsByQuantity
+ : SUBPARTITIONS NUMBER_ (STORE IN LP_ tablespaceName (COMMA_ tablespaceName)* RP_)?
+ ;
+
+addSystemPartitionClause
+ : tablePartitionDescription? updateIndexClauses?
+ ;
+
+addHashPartitionClause
+ : partitioningStorageClause updateIndexClauses? parallelClause? readOnlyClause? indexingClause?
;
dropTablePartition
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/OracleKeyword.g4 b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/OracleKeyword.g4
index 2a1dd4e..f8b8ba2 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/OracleKeyword.g4
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/OracleKeyword.g4
@@ -1423,10 +1423,26 @@ NONEDITIONABLE
: N O N E D I T I O N A B L E
;
+DEPENDENT
+ : D E P E N D E N T
+ ;
+
INDEXES
: I N D E X E S
;
+SHRINK
+ : S H R I N K
+ ;
+
+SPACE
+ : S P A C E
+ ;
+
+COMPACT
+ : C O M P A C T
+ ;
+
SUPPLEMENTAL
: S U P P L E M E N T A L
;
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/ddl/alter-table.xml b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/ddl/alter-table.xml
index 043c24f..f9901f0 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/ddl/alter-table.xml
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/ddl/alter-table.xml
@@ -1094,4 +1094,33 @@
<alter-table sql-case-id="alter_table_drop_partition_update_all_index_noparallel">
<table name="t_order" start-index="12" stop-index="18"/>
</alter-table>
+
+ <alter-table sql-case-id="alter_table_add_hash_partition1">
+ <table name="t_order" start-index="12" stop-index="18"/>
+ </alter-table>
+
+ <alter-table sql-case-id="alter_table_add_hash_partition2">
+ <table name="t_order" start-index="12" stop-index="18"/>
+ </alter-table>
+
+ <alter-table sql-case-id="alter_table_modify_hash_partition">
+ <table name="t_order" start-index="12" stop-index="18"/>
+ </alter-table>
+
+ <alter-table sql-case-id="alter_table_modify_list_partition">
+ <table name="t_order" start-index="12" stop-index="18"/>
+ </alter-table>
+
+ <alter-table sql-case-id="alter_table_modify_range_partition">
+ <table name="t_order" start-index="12" stop-index="18"/>
+ </alter-table>
+
+ <alter-table sql-case-id="alter_table_move_partition">
+ <table name="t_order" start-index="12" stop-index="18"/>
+ </alter-table>
+
+ <alter-table sql-case-id="alter_table_coalesce_partition">
+ <table name="t_order" start-index="12" stop-index="18"/>
+ </alter-table>
+
</sql-parser-test-cases>
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/ddl/alter.xml b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/ddl/alter.xml
index 3c942e3..8c32858 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/ddl/alter.xml
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/ddl/alter.xml
@@ -133,6 +133,13 @@
<sql-case id="alter_table_drop_partition_update_all_index_subpartition" value="ALTER TABLE t_order DROP PARTITION list_p_order UPDATE INDEXES (order_index (SUBPARTITION))" db-types="Oracle" />
<sql-case id="alter_table_drop_partition_update_global_index_parallel" value="ALTER TABLE t_order DROP PARTITION list_p_order UPDATE GLOBAL INDEXES PARALLEL" db-types="Oracle" />
<sql-case id="alter_table_drop_partition_update_all_index_noparallel" value="ALTER TABLE t_order DROP PARTITION list_p_order UPDATE INDEXES NOPARALLEL" db-types="Oracle" />
+ <sql-case id="alter_table_add_hash_partition1" value="ALTER TABLE t_order ADD PARTITION hash_partition TABLESPACE spaceName" db-types="Oracle" />
+ <sql-case id="alter_table_add_hash_partition2" value="ALTER TABLE t_order ADD PARTITION hash_partition OVERFLOW TABLESPACE spaceName" db-types="Oracle" />
+ <sql-case id="alter_table_modify_hash_partition" value="ALTER TABLE t_order MODIFY PARTITION hash_partition READ ONLY" db-types="Oracle" />
+ <sql-case id="alter_table_modify_list_partition" value="ALTER TABLE t_order MODIFY PARTITION hash_partition INDEXING ON" db-types="Oracle" />
+ <sql-case id="alter_table_modify_range_partition" value="ALTER TABLE t_order MODIFY PARTITION hash_partition ADD SUBPARTITION P1 VALUES('COMPLETE');" db-types="Oracle" />
+ <sql-case id="alter_table_move_partition" value="ALTER TABLE t_order MOVE PARTITION p0 TABLESPACE space0" db-types="Oracle" />
+ <sql-case id="alter_table_coalesce_partition" value="ALTER TABLE t_order COALESCE PARTITION" db-types="Oracle" />
<!-- alter index test-->
<sql-case id="alter_index" value="ALTER INDEX order_index REBUILD PARALLEL" db-types="Oracle" />
<sql-case id="alter_index_with_space" value=" ALTER INDEX