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/01/24 06:00:32 UTC

[shardingsphere] branch master updated: Feature: add syntax for alter table in g4 files and unit tests, for 6480 issue. (#9123)

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 18d230e  Feature: add syntax for alter table in g4 files and unit tests, for 6480 issue. (#9123)
18d230e is described below

commit 18d230eba55418a89a76ade5bdfac6c2adf28e9e
Author: coco <co...@gmail.com>
AuthorDate: Sun Jan 24 13:59:49 2021 +0800

    Feature: add syntax for alter table in g4 files and unit tests, for 6480 issue. (#9123)
    
    * feature: add syntax for alter table in g4 files and unit tests.
    
    * style: modify code style.
---
 .../src/main/antlr4/imports/oracle/DDLStatement.g4 |  34 ++++--
 .../src/main/antlr4/imports/oracle/Keyword.g4      |   4 +
 .../main/antlr4/imports/oracle/OracleKeyword.g4    |   8 ++
 .../src/main/resources/case/ddl/alter-table.xml    | 117 ++++++++++++++++++++-
 .../src/main/resources/sql/supported/ddl/alter.xml |  12 +++
 5 files changed, 162 insertions(+), 13 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 bdc5619..9b2fa64 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
@@ -28,7 +28,7 @@ createIndex
     ;
 
 alterTable
-    : ALTER TABLE tableName alterDefinitionClause
+    : ALTER TABLE tableName memOptimizeClause alterDefinitionClause enableDisableClauses
     ;
 
 // TODO hongjun throw exeption when alter index on oracle
@@ -88,14 +88,6 @@ createObjectTableClause
     : OF objectName objectTableSubstitution? (LP_ objectProperties RP_)? (ON COMMIT (DELETE | PRESERVE) ROWS)?
     ;
 
-createMemOptimizeClause
-    : (MEMOPTIMIZE FOR READ)? (MEMOPTIMIZE FOR WRITE)? 
-    ;    
-
-createParentClause
-    : (PARENT tableName)?
-    ;
-
 relationalProperties
     : relationalProperty (COMMA_ relationalProperty)*
     ;
@@ -378,3 +370,27 @@ renameIndexClause
 objectTableSubstitution
     : NOT? SUBSTITUTABLE AT ALL LEVELS
     ;
+
+memOptimizeClause
+    : memOptimizeReadClause? memOptimizeWriteClause?
+    ;
+
+memOptimizeReadClause
+    : (MEMOPTIMIZE FOR READ | NO MEMOPTIMIZE FOR READ)
+    ;
+
+memOptimizeWriteClause
+    : (MEMOPTIMIZE FOR WRITE | NO MEMOPTIMIZE FOR WRITE)
+    ;
+
+enableDisableClauses
+    : (enableDisableClause | enableDisableOthers)?
+    ;
+
+enableDisableClause
+    : (ENABLE | DISABLE) (VALIDATE |NO VALIDATE)? ((UNIQUE columnName (COMMA_ columnName)*) | PRIMARY KEY | constraintWithName) usingIndexClause? exceptionsClause? CASCADE? ((KEEP | DROP) INDEX)?
+    ;
+
+enableDisableOthers
+    : (ENABLE | DISABLE) (TABLE LOCK | ALL TRIGGERS | CONTAINER_MAP | CONTAINERS_DEFAULT)
+    ;
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/Keyword.g4 b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/Keyword.g4
index c6eaa80..7b272ca 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/Keyword.g4
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/Keyword.g4
@@ -550,3 +550,7 @@ NUMERIC
 FLOAT
     : F L O A T
     ;
+
+TRIGGERS
+    : T R I G G E R S
+    ;
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 bb38583..711cc42 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
@@ -818,3 +818,11 @@ IDENTIFIER
 WORK
     : W O R K
     ;
+
+CONTAINER_MAP
+    : C O N T A I N E R UL_ M A P
+    ;
+
+CONTAINERS_DEFAULT
+    : C O N T A I N E R S UL_ D E F A U L T
+    ;
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 7b55ccf..973fcab7 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
@@ -901,18 +901,127 @@
     </alter-table>
 
     <alter-table sql-case-id="alter_table_set_schema">
-        <table name="t_order" start-index="12" stop-index="18" />
+        <table name="t_order" start-index="12" stop-index="18"/>
     </alter-table>
 
     <alter-table sql-case-id="alter_table_attach_partition">
-        <table name="t_order" stop-index="18" start-index="12"/>
+        <table name="t_order" start-index="12" stop-index="18"/>
     </alter-table>
 
     <alter-table sql-case-id="alter_table_detach_partition">
-        <table name="t_order" stop-index="18" start-index="12"/>
+        <table name="t_order" start-index="12" stop-index="18"/>
     </alter-table>
 
     <alter-table sql-case-id="alter_table_in_hash_partitioned_table">
-        <table name="t_order" stop-index="18" start-index="12"/>
+        <table name="t_order" start-index="12" stop-index="18"/>
+    </alter-table>
+
+    <alter-table sql-case-id="alter_table_with_optimize_memory_read">
+        <table name="t_log" start-index="12" stop-index="16"/>
+        <add-column>
+            <column-definition type="VARCHAR" start-index="43" stop-index="58">
+                <column name="name" />
+            </column-definition>
+        </add-column>
+    </alter-table>
+
+    <alter-table sql-case-id="alter_table_with_no_optimize_memory_write">
+        <table name="t_log" start-index="12" stop-index="16"/>
+        <add-column>
+            <column-definition type="VARCHAR" start-index="47" stop-index="62">
+                <column name="name" />
+            </column-definition>
+        </add-column>
+    </alter-table>
+
+    <alter-table sql-case-id="alter_table_with_enable_validate">
+        <table name="t_log" start-index="12" stop-index="16"/>
+        <add-column>
+            <column-definition type="VARCHAR" start-index="22" stop-index="37">
+                <column name="name" />
+            </column-definition>
+        </add-column>
+    </alter-table>
+
+    <alter-table sql-case-id="alter_table_with_primary_key">
+        <table name="t_log" start-index="12" stop-index="16"/>
+        <add-column>
+            <column-definition type="VARCHAR" start-index="22" stop-index="37">
+                <column name="name" />
+            </column-definition>
+        </add-column>
+    </alter-table>
+
+    <alter-table sql-case-id="alter_table_with_index_clause">
+        <table name="t_log" start-index="12" stop-index="16"/>
+        <add-column>
+            <column-definition type="VARCHAR" start-index="22" stop-index="37">
+                <column name="name" />
+            </column-definition>
+        </add-column>
+    </alter-table>
+
+    <alter-table sql-case-id="alter_table_with_exception_clause">
+        <table name="t_log" start-index="12" stop-index="16"/>
+        <add-column>
+            <column-definition type="VARCHAR" start-index="22" stop-index="37">
+                <column name="name" />
+            </column-definition>
+        </add-column>
     </alter-table>
+
+    <alter-table sql-case-id="alter_table_with_cascade">
+        <table name="t_log" start-index="12" stop-index="16"/>
+        <add-column>
+            <column-definition type="VARCHAR" start-index="22" stop-index="37">
+                <column name="name" />
+            </column-definition>
+        </add-column>
+    </alter-table>
+
+    <alter-table sql-case-id="alter_table_with_keep_index">
+        <table name="t_log" start-index="12" stop-index="16"/>
+        <add-column>
+            <column-definition type="VARCHAR" start-index="22" stop-index="37">
+                <column name="name" />
+            </column-definition>
+        </add-column>
+    </alter-table>
+
+    <alter-table sql-case-id="alter_table_with_enable_table_lock">
+        <table name="t_log" start-index="12" stop-index="16"/>
+        <add-column>
+            <column-definition type="VARCHAR" start-index="22" stop-index="37">
+                <column name="name" />
+            </column-definition>
+        </add-column>
+    </alter-table>
+
+    <alter-table sql-case-id="alter_table_with_enable_all_triggers">
+        <table name="t_log" start-index="12" stop-index="16"/>
+        <add-column>
+            <column-definition type="VARCHAR" start-index="22" stop-index="37">
+                <column name="name" />
+            </column-definition>
+        </add-column>
+    </alter-table>
+
+    <alter-table sql-case-id="alter_table_with_disable_container_map">
+        <table name="t_log" start-index="12" stop-index="16"/>
+        <add-column>
+            <column-definition type="VARCHAR" start-index="22" stop-index="37">
+                <column name="name" />
+            </column-definition>
+        </add-column>
+    </alter-table>
+
+    <alter-table sql-case-id="alter_table_with_disable_containers_default">
+        <table name="t_log" start-index="12" stop-index="16"/>
+        <add-column>
+            <column-definition type="VARCHAR" start-index="22" stop-index="37">
+                <column name="name" />
+            </column-definition>
+        </add-column>
+    </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 fb51932..5e0ff5e 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
@@ -110,6 +110,18 @@
     <sql-case id="alter_table_attach_partition" value="ALTER TABLE t_order ATTACH PARTITION measurement_y2016m07 FOR VALUES FROM ('2016-07-01') TO ('2016-08-01')" db-types="PostgreSQL"/>
     <sql-case id="alter_table_detach_partition" value="ALTER TABLE t_order ATTACH PARTITION measurement_y2016m07 FOR VALUES FROM ('2016-07-01') TO ('2016-08-01')" db-types="PostgreSQL"/>
     <sql-case id="alter_table_in_hash_partitioned_table" value="ALTER TABLE t_order ATTACH PARTITION orders_p4 FOR VALUES WITH (MODULUS 4, REMAINDER 3)" db-types="PostgreSQL" />
+    <sql-case id="alter_table_with_optimize_memory_read" value="ALTER TABLE t_log MEMOPTIMIZE FOR READ ADD name VARCHAR(10)" db-types="Oracle" />
+    <sql-case id="alter_table_with_no_optimize_memory_write" value="ALTER TABLE t_log NO MEMOPTIMIZE FOR WRITE ADD name VARCHAR(10)" db-types="Oracle" />
+    <sql-case id="alter_table_with_enable_validate" value="ALTER TABLE t_log ADD name VARCHAR(10) ENABLE VALIDATE PRIMARY KEY" db-types="Oracle" />
+    <sql-case id="alter_table_with_primary_key" value="ALTER TABLE t_log ADD name VARCHAR(10) ENABLE PRIMARY KEY" db-types="Oracle" />
+    <sql-case id="alter_table_with_index_clause" value="ALTER TABLE t_log ADD name VARCHAR(10) ENABLE PRIMARY KEY USING INDEX t_log" db-types="Oracle" />
+    <sql-case id="alter_table_with_exception_clause" value="ALTER TABLE t_log ADD name VARCHAR(10) DISABLE PRIMARY KEY EXCEPTIONS INTO t_log" db-types="Oracle" />
+    <sql-case id="alter_table_with_cascade" value="ALTER TABLE t_log ADD name VARCHAR(10) DISABLE PRIMARY KEY CASCADE" db-types="Oracle" />
+    <sql-case id="alter_table_with_keep_index" value="ALTER TABLE t_log ADD name VARCHAR(10) DISABLE PRIMARY KEY KEEP INDEX" db-types="Oracle" />
+    <sql-case id="alter_table_with_enable_table_lock" value="ALTER TABLE t_log ADD name VARCHAR(10) ENABLE TABLE LOCK" db-types="Oracle" />
+    <sql-case id="alter_table_with_enable_all_triggers" value="ALTER TABLE t_log ADD name VARCHAR(10) ENABLE ALL TRIGGERS" db-types="Oracle" />
+    <sql-case id="alter_table_with_disable_container_map" value="ALTER TABLE t_log ADD name VARCHAR(10) DISABLE CONTAINER_MAP" db-types="Oracle" />
+    <sql-case id="alter_table_with_disable_containers_default" value="ALTER TABLE t_log ADD name VARCHAR(10) DISABLE CONTAINERS_DEFAULT" db-types="Oracle" />
     
 <!--    alter index test-->
     <sql-case id="alter_index" value="ALTER INDEX order_index REBUILD PARALLEL" db-types="Oracle" />