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/02/07 02:42:14 UTC

[shardingsphere] branch master updated: feature: truncate table in oracle. (#9306)

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 d375b5c  feature: truncate table in oracle. (#9306)
d375b5c is described below

commit d375b5c8971dcca64572ee7d343483c082923915
Author: coco <co...@gmail.com>
AuthorDate: Sun Feb 7 10:41:53 2021 +0800

    feature: truncate table in oracle. (#9306)
    
    * feature: truncate table in oracle.
    
    * style: add last line in DDLStatement.g4.
---
 .../src/main/antlr4/imports/oracle/DDLStatement.g4   | 10 +++++++++-
 .../src/main/antlr4/imports/oracle/OracleKeyword.g4  | 12 ++++++++++++
 .../src/main/resources/case/ddl/truncate.xml         | 20 ++++++++++++++++++++
 .../main/resources/sql/supported/ddl/truncate.xml    |  5 +++++
 4 files changed, 46 insertions(+), 1 deletion(-)

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 9b2fa64..66e4963 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
@@ -45,7 +45,7 @@ dropIndex
     ;
 
 truncateTable
-    : TRUNCATE TABLE tableName
+    : TRUNCATE TABLE tableName materializedViewLogClause? storageClause? CASCADE?
     ;
 
 createTableSpecification
@@ -394,3 +394,11 @@ enableDisableClause
 enableDisableOthers
     : (ENABLE | DISABLE) (TABLE LOCK | ALL TRIGGERS | CONTAINER_MAP | CONTAINERS_DEFAULT)
     ;
+
+materializedViewLogClause
+    : (PRESERVE | PURGE) MATERIALIZED VIEW LOG
+    ;
+
+storageClause
+    : (DROP (ALL)? | REUSE) STORAGE
+    ;
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 9f44d33..c0881d2 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
@@ -838,3 +838,15 @@ NOWAIT
 BATCH
     : B A T C H
     ;
+
+LOG
+    : L O G
+    ;
+
+REUSE
+    : R E U S E
+    ;
+
+STORAGE
+    : S T O R A G E
+    ;
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/ddl/truncate.xml b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/ddl/truncate.xml
index c100f45..20c5fc5 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/ddl/truncate.xml
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/ddl/truncate.xml
@@ -57,4 +57,24 @@
     <truncate sql-case-id="truncate_table_with_bracket">
         <table name="t_order" start-delimiter="[" end-delimiter="]" start-index="15" stop-index="23" />
     </truncate>
+
+    <truncate sql-case-id="truncate_table_with_preserve_view_log">
+        <table name="t_log" start-index="15" stop-index="19" />
+    </truncate>
+
+    <truncate sql-case-id="truncate_table_with_purge_view_log">
+        <table name="t_log" start-index="15" stop-index="19" />
+    </truncate>
+
+    <truncate sql-case-id="truncate_table_with_drop_all_storage">
+        <table name="t_log" start-index="15" stop-index="19" />
+    </truncate>
+
+    <truncate sql-case-id="truncate_table_with_reuse_all_storage">
+        <table name="t_log" start-index="15" stop-index="19" />
+    </truncate>
+
+    <truncate sql-case-id="truncate_table_with_cascade">
+        <table name="t_log" start-index="15" stop-index="19" />
+    </truncate>
 </sql-parser-test-cases>
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/ddl/truncate.xml b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/ddl/truncate.xml
index ff878cd..3929cf6 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/ddl/truncate.xml
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/ddl/truncate.xml
@@ -28,4 +28,9 @@
     <sql-case id="truncate_tables" value="TRUNCATE TABLE t_order_item, t_order" db-types="PostgreSQL" />
     <sql-case id="truncate_table_with_asterisk" value="TRUNCATE TABLE t_order *" db-types="PostgreSQL" />
     <sql-case id="truncate_table_with_bracket" value="TRUNCATE TABLE [t_order]" db-types="SQLServer" />
+    <sql-case id="truncate_table_with_preserve_view_log" value="TRUNCATE TABLE t_log PRESERVE MATERIALIZED VIEW LOG" db-types="Oracle" />
+    <sql-case id="truncate_table_with_purge_view_log" value="TRUNCATE TABLE t_log PURGE MATERIALIZED VIEW LOG" db-types="Oracle" />
+    <sql-case id="truncate_table_with_drop_all_storage" value="TRUNCATE TABLE t_log DROP STORAGE" db-types="Oracle" />
+    <sql-case id="truncate_table_with_reuse_all_storage" value="TRUNCATE TABLE t_log REUSE STORAGE" db-types="Oracle" />
+    <sql-case id="truncate_table_with_cascade" value="TRUNCATE TABLE t_log CASCADE" db-types="Oracle" />
 </sql-cases>