This is an automated email from the ASF dual-hosted git repository.

duanzhengqiang 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 fa110d7680a fix:Support Hive TRUNCATE TABLE statement parse (#36049)
fa110d7680a is described below

commit fa110d7680a7e1ec4b47188c85117a5d8eac11ce
Author: Claire <claire040...@163.com>
AuthorDate: Tue Jul 22 08:52:18 2025 +0800

    fix:Support Hive TRUNCATE TABLE statement parse (#36049)
    
    * support truncate table statement parse
    
    * update RELEASE-NOTES.md
---
 RELEASE-NOTES.md                                   |  1 +
 .../src/main/antlr4/imports/hive/DDLStatement.g4   |  4 ++
 .../sql/parser/autogen/HiveStatement.g4            |  1 +
 .../statement/type/HiveDDLStatementVisitor.java    |  9 ++++
 .../src/main/resources/case/ddl/truncate.xml       | 52 ++++++++++++++++++++++
 .../main/resources/sql/supported/ddl/truncate.xml  |  8 ++++
 6 files changed, 75 insertions(+)

diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md
index 7ca60f90d5e..4cc0a24dddd 100644
--- a/RELEASE-NOTES.md
+++ b/RELEASE-NOTES.md
@@ -63,6 +63,7 @@
 1. SQL Parser: Support Hive DROP TABLE statement parse - 
[#36018](https://github.com/apache/shardingsphere/pull/36018)
 1. SQL Parser: Support Hive USE DATABASE statement parse - 
[#36024](https://github.com/apache/shardingsphere/pull/36024)
 1. SQL Parser: Support Hive CREATE TABLE statement parse - 
[#36040](https://github.com/apache/shardingsphere/pull/36040)
+1. SQL Parser: Support Hive TRUNCATE TABLE statement parse - 
[#36049](https://github.com/apache/shardingsphere/pull/36049)
 
 ### Bug Fixes
 
diff --git 
a/parser/sql/dialect/hive/src/main/antlr4/imports/hive/DDLStatement.g4 
b/parser/sql/dialect/hive/src/main/antlr4/imports/hive/DDLStatement.g4
index 4d6d542ea28..ade28a89511 100644
--- a/parser/sql/dialect/hive/src/main/antlr4/imports/hive/DDLStatement.g4
+++ b/parser/sql/dialect/hive/src/main/antlr4/imports/hive/DDLStatement.g4
@@ -44,6 +44,10 @@ dropTable
     : DROP TABLE ifExists? tableList (PURGE)?
     ;
 
+truncateTable
+    : TRUNCATE (TABLE)? tableNameWithDb partitionSpec?
+    ;
+
 alterDatabaseSpecification_
     : SET DBPROPERTIES LP_ dbProperties RP_
     | SET OWNER (USER | ROLE) identifier
diff --git 
a/parser/sql/dialect/hive/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/HiveStatement.g4
 
b/parser/sql/dialect/hive/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/HiveStatement.g4
index 9a670673883..5677fef92b5 100644
--- 
a/parser/sql/dialect/hive/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/HiveStatement.g4
+++ 
b/parser/sql/dialect/hive/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/HiveStatement.g4
@@ -32,6 +32,7 @@ execute
     | use
     | createTable
     | dropTable
+    | truncateTable
     ) (SEMI_ EOF? | EOF)
     | EOF
     ;
diff --git 
a/parser/sql/dialect/hive/src/main/java/org/apache/shardingsphere/sql/parser/hive/visitor/statement/type/HiveDDLStatementVisitor.java
 
b/parser/sql/dialect/hive/src/main/java/org/apache/shardingsphere/sql/parser/hive/visitor/statement/type/HiveDDLStatementVisitor.java
index c84455f26c3..f2c48b295de 100644
--- 
a/parser/sql/dialect/hive/src/main/java/org/apache/shardingsphere/sql/parser/hive/visitor/statement/type/HiveDDLStatementVisitor.java
+++ 
b/parser/sql/dialect/hive/src/main/java/org/apache/shardingsphere/sql/parser/hive/visitor/statement/type/HiveDDLStatementVisitor.java
@@ -32,6 +32,7 @@ import 
org.apache.shardingsphere.sql.parser.autogen.HiveStatementParser.DataType
 import 
org.apache.shardingsphere.sql.parser.autogen.HiveStatementParser.DropDatabaseContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.HiveStatementParser.DropTableContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.HiveStatementParser.TableNameWithDbContext;
+import 
org.apache.shardingsphere.sql.parser.autogen.HiveStatementParser.TruncateTableContext;
 import 
org.apache.shardingsphere.sql.parser.hive.visitor.statement.HiveStatementVisitor;
 import 
org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.column.ColumnDefinitionSegment;
 import 
org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.constraint.ConstraintDefinitionSegment;
@@ -47,6 +48,8 @@ import 
org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.da
 import 
org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.table.DropTableStatement;
 import 
org.apache.shardingsphere.sql.parser.statement.core.value.collection.CollectionValue;
 import 
org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
+import 
org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.TruncateStatement;
+import java.util.Collections;
 
 /**
  * DDL statement visitor for Hive.
@@ -81,6 +84,12 @@ public final class HiveDDLStatementVisitor extends 
HiveStatementVisitor implemen
         return result;
     }
     
+    @SuppressWarnings("unchecked")
+    @Override
+    public ASTNode visitTruncateTable(final TruncateTableContext ctx) {
+        return new TruncateStatement(getDatabaseType(), 
Collections.singleton((SimpleTableSegment) visit(ctx.tableNameWithDb())));
+    }
+    
     @SuppressWarnings("unchecked")
     @Override
     public ASTNode visitCreateTable(final CreateTableContext ctx) {
diff --git a/test/it/parser/src/main/resources/case/ddl/truncate.xml 
b/test/it/parser/src/main/resources/case/ddl/truncate.xml
index 20c5fc5f3f8..824872e791e 100644
--- a/test/it/parser/src/main/resources/case/ddl/truncate.xml
+++ b/test/it/parser/src/main/resources/case/ddl/truncate.xml
@@ -77,4 +77,56 @@
     <truncate sql-case-id="truncate_table_with_cascade">
         <table name="t_log" start-index="15" stop-index="19" />
     </truncate>
+
+    <truncate sql-case-id="truncate_tablename">
+        <table name="test_table" start-index="9" stop-index="18" />
+    </truncate>
+
+    <truncate sql-case-id="truncate_with_db_tablename">
+        <table name="t_log" db-name="test_tb" start-index="9" stop-index="21" >
+            <owner name="test_tb" start-index="9" stop-index="15" />
+        </table>
+    </truncate>
+
+    <truncate sql-case-id="truncate_table_tablename">
+        <table name="test_table" start-index="15" stop-index="24" />
+    </truncate>
+
+    <truncate sql-case-id="truncate_with_table_db_tablename">
+        <table name="t_log" db-name="test_tb" start-index="15" stop-index="27" 
>
+            <owner name="test_tb" start-index="15" stop-index="21" />
+        </table>
+    </truncate>
+
+    <truncate sql-case-id="truncate_tablename_with_partition">
+        <table name="test_table" start-index="9" stop-index="18" />
+        <partition start-index="20" stop-index="42">
+            <partition-key name="dt" value="'2025-01-01'" />
+        </partition>
+    </truncate>
+
+    <truncate sql-case-id="truncate_table_tablename_with_partition">
+        <table name="test_table" start-index="15" stop-index="24" />
+        <partition start-index="26" stop-index="48">
+            <partition-key name="dt" value="'2025-01-01'" />
+        </partition>
+    </truncate>
+
+    <truncate sql-case-id="truncate_db_tablename_with_partition">
+        <table name="test_table" db-name="test_tb" start-index="9" 
stop-index="26" >
+            <owner name="test_tb" start-index="9" stop-index="15" />
+        </table>
+        <partition start-index="23" stop-index="45">
+            <partition-key name="dt" value="'2025-01-01'" />
+        </partition>
+    </truncate>
+
+    <truncate sql-case-id="truncate_table_db_tablename_with_partition">
+        <table name="test_table" db-name="test_tb" start-index="15" 
stop-index="32" >
+            <owner name="test_tb" start-index="15" stop-index="21" />
+        </table>
+        <partition start-index="35" stop-index="57">
+            <partition-key name="dt" value="'2025-01-01'" />
+        </partition>
+    </truncate>
 </sql-parser-test-cases>
diff --git a/test/it/parser/src/main/resources/sql/supported/ddl/truncate.xml 
b/test/it/parser/src/main/resources/sql/supported/ddl/truncate.xml
index beb94965a1e..7e73561cc7b 100644
--- a/test/it/parser/src/main/resources/sql/supported/ddl/truncate.xml
+++ b/test/it/parser/src/main/resources/sql/supported/ddl/truncate.xml
@@ -33,4 +33,12 @@
     <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-case id="truncate_tablename" value="TRUNCATE test_table" 
db-types="Hive" />
+    <sql-case id="truncate_with_db_tablename" value="TRUNCATE test_tb.t_log" 
db-types="Hive" />
+    <sql-case id="truncate_table_tablename" value="TRUNCATE TABLE test_table" 
db-types="Hive" />
+    <sql-case id="truncate_with_table_db_tablename" value="TRUNCATE TABLE 
test_tb.t_log" db-types="Hive" />
+    <sql-case id="truncate_tablename_with_partition" value="TRUNCATE 
test_table PARTITION (dt='2025-01-01')" db-types="Hive" />
+    <sql-case id="truncate_table_tablename_with_partition" value="TRUNCATE 
TABLE test_table PARTITION (dt='2025-01-01')" db-types="Hive" />
+    <sql-case id="truncate_db_tablename_with_partition" value="TRUNCATE 
test_tb.test_table PARTITION (dt='2025-01-01')" db-types="Hive" />
+    <sql-case id="truncate_table_db_tablename_with_partition" value="TRUNCATE 
TABLE test_tb.test_table PARTITION (dt='2025-01-01')" db-types="Hive" />
 </sql-cases>

Reply via email to