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 078bfe63feb fix:Support Hive ALTER PARTITION statement parse (#36072)
078bfe63feb is described below
commit 078bfe63febac576b67dbbe7b68fdf3075eb76f7
Author: Claire <[email protected]>
AuthorDate: Mon Jul 28 08:53:00 2025 +0800
fix:Support Hive ALTER PARTITION statement parse (#36072)
* update alter partition statement parse
* update RELEASE-NOTES.md
* update code
* Update RELEASE-NOTES.md
* Update RELEASE-NOTES.md
---------
Co-authored-by: Zhengqiang Duan <[email protected]>
---
RELEASE-NOTES.md | 1 +
.../src/main/antlr4/imports/hive/DDLStatement.g4 | 17 +++
.../src/main/antlr4/imports/hive/HiveKeyword.g4 | 20 ++++
.../sql/parser/autogen/HiveStatement.g4 | 1 +
.../statement/type/HiveDDLStatementVisitor.java | 8 ++
.../core/database/visitor/SQLVisitorRule.java | 2 +
.../src/main/resources/case/ddl/alter-table.xml | 120 +++++++++++++++++++++
.../resources/sql/supported/ddl/alter-table.xml | 30 ++++++
8 files changed, 199 insertions(+)
diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md
index 1ad5b27a391..52ccdd6813a 100644
--- a/RELEASE-NOTES.md
+++ b/RELEASE-NOTES.md
@@ -66,6 +66,7 @@
1. SQL Parser: Support Hive TRUNCATE TABLE statement parse -
[#36049](https://github.com/apache/shardingsphere/pull/36049)
1. SQL Parser: Support Hive ALTER TABLE statement parse -
[#36066](https://github.com/apache/shardingsphere/pull/36066)
1. SQL Binder: Fix is unable to find the outer table in the
ExistsSubqueryExpressionBinder -
[#36068](https://github.com/apache/shardingsphere/pull/36068)
+1. SQL Parser: Support Hive ALTER PARTITION statement parse -
[#36072](https://github.com/apache/shardingsphere/pull/36072)
### 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 cc97cc540ae..0ee7ca3d36d 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
@@ -67,6 +67,13 @@ alterTable
| alterTableCommonClause partitionSpec? COMPACT string_ (AND WAIT)?
clusteredIntoClause? orderByClause? poolClause? tblpropertiesClause?
| alterTableCommonClause partitionSpec? CONCATENATE
| alterTableCommonClause partitionSpec? UPDATE COLUMNS
+ | alterTableCommonClause ADD ifNotExists? partitionSpec storageLocation?
(COMMA_ partitionSpec storageLocation?)*
+ | alterTableCommonClause DROP ifExists? partitionSpec (COMMA_
partitionSpec)* (IGNORE PROTECTION)? PURGE?
+ | alterTableCommonClause partitionSpec RENAME TO partitionSpec
+ | alterTableCommonClause EXCHANGE partitionSpec WITH TABLE tableName
+ | alterTableCommonClause ARCHIVE partitionSpec
+ | alterTableCommonClause UNARCHIVE partitionSpec
+ | alterTableCommonClause RECOVER PARTITIONS
;
alterDatabaseSpecification_
@@ -351,3 +358,13 @@ poolClause
tblpropertiesClause
: WITH OVERWRITE tblProperties
;
+
+msckStatement
+ : MSCK REPAIR? TABLE tableName msckAction?
+ ;
+
+msckAction
+ : ADD PARTITIONS
+ | DROP PARTITIONS
+ | SYNC PARTITIONS
+ ;
diff --git
a/parser/sql/dialect/hive/src/main/antlr4/imports/hive/HiveKeyword.g4
b/parser/sql/dialect/hive/src/main/antlr4/imports/hive/HiveKeyword.g4
index e471da5ce2e..2b5af367d38 100644
--- a/parser/sql/dialect/hive/src/main/antlr4/imports/hive/HiveKeyword.g4
+++ b/parser/sql/dialect/hive/src/main/antlr4/imports/hive/HiveKeyword.g4
@@ -3313,3 +3313,23 @@ NOVALIDEATE
POOL
: P O O L
;
+
+ARCHIVE
+ : A R C H I V E
+ ;
+
+UNARCHIVE
+ : U N A R C H I V E
+ ;
+
+PROTECTION
+ : P R O T E C T I O N
+ ;
+
+MSCK
+ : M S C K
+ ;
+
+SYNC
+ : S Y N C
+ ;
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 a4d029e4b66..fbd1cda5a75 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
@@ -33,6 +33,7 @@ execute
| createTable
| dropTable
| truncateTable
+ | msckStatement
| alterTable
) (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 1908723fdea..79b3b597b32 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
@@ -34,6 +34,7 @@ import
org.apache.shardingsphere.sql.parser.autogen.HiveStatementParser.DropTabl
import
org.apache.shardingsphere.sql.parser.autogen.HiveStatementParser.TableNameWithDbContext;
import
org.apache.shardingsphere.sql.parser.autogen.HiveStatementParser.TruncateTableContext;
import
org.apache.shardingsphere.sql.parser.autogen.HiveStatementParser.AlterTableContext;
+import
org.apache.shardingsphere.sql.parser.autogen.HiveStatementParser.MsckStatementContext;
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;
@@ -100,6 +101,13 @@ public final class HiveDDLStatementVisitor extends
HiveStatementVisitor implemen
|| "REBALANCE".equalsIgnoreCase(compactionType);
}
+ @Override
+ public ASTNode visitMsckStatement(final MsckStatementContext ctx) {
+ AlterTableStatement result = new
AlterTableStatement(getDatabaseType());
+ result.setTable((SimpleTableSegment) visit(ctx.tableName()));
+ return result;
+ }
+
@SuppressWarnings("unchecked")
@Override
public ASTNode visitDropTable(final DropTableContext ctx) {
diff --git
a/parser/sql/engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/visitor/SQLVisitorRule.java
b/parser/sql/engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/visitor/SQLVisitorRule.java
index a7701d774c9..9f41c4bb1df 100644
---
a/parser/sql/engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/visitor/SQLVisitorRule.java
+++
b/parser/sql/engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/visitor/SQLVisitorRule.java
@@ -55,6 +55,8 @@ public enum SQLVisitorRule {
ALTER_TABLE("AlterTable", SQLStatementType.DDL),
+ MSCK("MsckStatement", SQLStatementType.DDL),
+
ALTER_TYPE("AlterType", SQLStatementType.DDL),
ALTER_AGGREGATE("AlterAggregate", SQLStatementType.DDL),
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 d5a3d05f154..24b52be6c10 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
@@ -1992,4 +1992,124 @@
<alter-table sql-case-id="alter_table_partition_update_columns">
<table name="parquet_event_log" start-index="12" stop-index="28" />
</alter-table>
+
+ <alter-table sql-case-id="alter_table_add_partition_basic">
+ <table name="test_table" start-index="12" stop-index="21" />
+ </alter-table>
+
+ <alter-table sql-case-id="alter_table_add_more_partition">
+ <table name="test_table" start-index="12" stop-index="21" />
+ </alter-table>
+
+ <alter-table sql-case-id="alter_table_add_partition_with_if_not_exists">
+ <table name="test_table" start-index="12" stop-index="21" />
+ </alter-table>
+
+ <alter-table sql-case-id="alter_table_add_partition_with_location">
+ <table name="test_table" start-index="12" stop-index="21" />
+ </alter-table>
+
+ <alter-table sql-case-id="alter_table_add_partition_with_both_options">
+ <table name="test_table" start-index="12" stop-index="21" />
+ </alter-table>
+
+ <alter-table sql-case-id="alter_table_rename_partition_basic">
+ <table name="sales" start-index="12" stop-index="16" />
+ </alter-table>
+
+ <alter-table sql-case-id="alter_table_exchange_partition_basic">
+ <table name="target_table" start-index="12" stop-index="23" />
+ </alter-table>
+
+ <alter-table sql-case-id="alter_table_exchange_partition_multiple">
+ <table name="target_table" start-index="12" stop-index="23" />
+ </alter-table>
+
+ <alter-table sql-case-id="alter_table_set_partition_retention_basic">
+ <table name="log_data" start-index="12" stop-index="19" />
+ </alter-table>
+
+ <alter-table
sql-case-id="alter_table_set_partition_retention_with_discover">
+ <table name="log_data" start-index="12" stop-index="19" />
+ </alter-table>
+
+ <alter-table sql-case-id="msck_check_table">
+ <table name="sales" start-index="11" stop-index="15" />
+ </alter-table>
+
+ <alter-table sql-case-id="msck_repair_table_basic">
+ <table name="sales" start-index="18" stop-index="22" />
+ </alter-table>
+
+ <alter-table sql-case-id="msck_check_table_add">
+ <table name="sales" start-index="11" stop-index="15" />
+ </alter-table>
+
+ <alter-table sql-case-id="msck_check_table_drop">
+ <table name="sales" start-index="11" stop-index="15" />
+ </alter-table>
+
+ <alter-table sql-case-id="msck_check_table_sync">
+ <table name="sales" start-index="11" stop-index="15" />
+ </alter-table>
+
+ <alter-table sql-case-id="msck_repair_table_add">
+ <table name="sales" start-index="18" stop-index="22" />
+ </alter-table>
+
+ <alter-table sql-case-id="msck_repair_table_drop">
+ <table name="sales" start-index="18" stop-index="22" />
+ </alter-table>
+
+ <alter-table sql-case-id="msck_repair_table_sync">
+ <table name="sales" start-index="18" stop-index="22" />
+ </alter-table>
+
+ <alter-table sql-case-id="alter_table_recover_partitions_emr">
+ <table name="sales" start-index="12" stop-index="16" />
+ </alter-table>
+
+ <alter-table sql-case-id="alter_table_drop_partition_basic">
+ <table name="page_view" start-index="12" stop-index="20" />
+ </alter-table>
+
+ <alter-table sql-case-id="alter_table_drop_partition_if_exists">
+ <table name="page_view" start-index="12" stop-index="20" />
+ </alter-table>
+
+ <alter-table sql-case-id="alter_table_drop_partition_purge">
+ <table name="page_view" start-index="12" stop-index="20" />
+ </alter-table>
+
+ <alter-table sql-case-id="alter_table_drop_partition_ignore_protection">
+ <table name="page_view" start-index="12" stop-index="20" />
+ </alter-table>
+
+ <alter-table sql-case-id="alter_table_drop_partition_if_exists_purge">
+ <table name="page_view" start-index="12" stop-index="20" />
+ </alter-table>
+
+ <alter-table
sql-case-id="alter_table_drop_partition_if_exists_ignore_protection">
+ <table name="page_view" start-index="12" stop-index="20" />
+ </alter-table>
+
+ <alter-table
sql-case-id="alter_table_drop_multiple_partitions_if_exists_purge">
+ <table name="page_view" start-index="12" stop-index="20" />
+ </alter-table>
+
+ <alter-table sql-case-id="alter_table_drop_partition_all_options">
+ <table name="page_view" start-index="12" stop-index="20" />
+ </alter-table>
+
+ <alter-table
sql-case-id="alter_table_drop_multiple_partitions_all_options">
+ <table name="page_view" start-index="12" stop-index="20" />
+ </alter-table>
+
+ <alter-table sql-case-id="alter_table_archive_partition_basic">
+ <table name="log_table" start-index="12" stop-index="20" />
+ </alter-table>
+
+ <alter-table sql-case-id="alter_table_unarchive_partition_basic">
+ <table name="log_table" start-index="12" stop-index="20" />
+ </alter-table>
</sql-parser-test-cases>
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 2abafce1fab..045a2c37f2f 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
@@ -294,4 +294,34 @@
<sql-case id="alter_table_partition_concatenate" value="ALTER TABLE
sales_orc PARTITION (region='asia', dt='2025-07-23') CONCATENATE"
db-types="Hive" />
<sql-case id="alter_table_update_columns_basic" value="ALTER TABLE
avro_user_data UPDATE COLUMNS" db-types="Hive" />
<sql-case id="alter_table_partition_update_columns" value="ALTER TABLE
parquet_event_log PARTITION (event_type='click') UPDATE COLUMNS"
db-types="Hive" />
+ <sql-case id="alter_table_add_partition_basic" value="ALTER TABLE
test_table ADD PARTITION (part_col='part_value')" db-types="Hive" />
+ <sql-case id="alter_table_add_more_partition" value="ALTER TABLE
test_table ADD PARTITION (dt='2008-08-08', country='us')" db-types="Hive" />
+ <sql-case id="alter_table_add_partition_with_if_not_exists" value="ALTER
TABLE test_table ADD IF NOT EXISTS PARTITION (part_col='part_value')"
db-types="Hive" />
+ <sql-case id="alter_table_add_partition_with_location" value="ALTER TABLE
test_table ADD PARTITION (part_col='part_value') LOCATION
'/user/hive/warehouse/test_table/part_value'" db-types="Hive" />
+ <sql-case id="alter_table_add_partition_with_both_options" value="ALTER
TABLE test_table ADD IF NOT EXISTS PARTITION (part_col='part_value') LOCATION
'/user/hive/warehouse/test_partition'" db-types="Hive" />
+ <sql-case id="alter_table_rename_partition_basic" value="ALTER TABLE sales
PARTITION (dt='2025-07-01') RENAME TO PARTITION (dt='20250701')"
db-types="Hive" />
+ <sql-case id="alter_table_exchange_partition_basic" value="ALTER TABLE
target_table EXCHANGE PARTITION (dt='2025-07-25') WITH TABLE source_table"
db-types="Hive" />
+ <sql-case id="alter_table_exchange_partition_multiple" value="ALTER TABLE
target_table EXCHANGE PARTITION (dt='2025-07-25', region='asia') WITH TABLE
source_table" db-types="Hive" />
+ <sql-case id="alter_table_set_partition_retention_basic" value="ALTER
TABLE log_data SET TBLPROPERTIES ('partition.retention.period'='30d')"
db-types="Hive" />
+ <sql-case id="alter_table_set_partition_retention_with_discover"
value="ALTER TABLE log_data SET TBLPROPERTIES
('partition.retention.period'='7d', 'discover.partitions'='true')"
db-types="Hive" />
+ <sql-case id="msck_check_table" value="MSCK TABLE sales" db-types="Hive" />
+ <sql-case id="msck_repair_table_basic" value="MSCK REPAIR TABLE sales"
db-types="Hive" />
+ <sql-case id="msck_check_table_add" value="MSCK TABLE sales ADD
PARTITIONS" db-types="Hive" />
+ <sql-case id="msck_check_table_drop" value="MSCK TABLE sales DROP
PARTITIONS" db-types="Hive" />
+ <sql-case id="msck_check_table_sync" value="MSCK TABLE sales SYNC
PARTITIONS" db-types="Hive" />
+ <sql-case id="msck_repair_table_add" value="MSCK REPAIR TABLE sales ADD
PARTITIONS" db-types="Hive" />
+ <sql-case id="msck_repair_table_drop" value="MSCK REPAIR TABLE sales DROP
PARTITIONS" db-types="Hive" />
+ <sql-case id="msck_repair_table_sync" value="MSCK REPAIR TABLE sales SYNC
PARTITIONS" db-types="Hive" />
+ <sql-case id="alter_table_recover_partitions_emr" value="ALTER TABLE sales
RECOVER PARTITIONS" db-types="Hive" />
+ <sql-case id="alter_table_drop_partition_basic" value="ALTER TABLE
page_view DROP PARTITION (dt='2008-08-08', country='us')" db-types="Hive" />
+ <sql-case id="alter_table_drop_partition_if_exists" value="ALTER TABLE
page_view DROP IF EXISTS PARTITION (dt='2008-08-08', country='us')"
db-types="Hive" />
+ <sql-case id="alter_table_drop_partition_purge" value="ALTER TABLE
page_view DROP PARTITION (dt='2008-08-08', country='us') PURGE" db-types="Hive"
/>
+ <sql-case id="alter_table_drop_partition_ignore_protection" value="ALTER
TABLE page_view DROP PARTITION (dt='2008-08-08', country='us') IGNORE
PROTECTION" db-types="Hive" />
+ <sql-case id="alter_table_drop_partition_if_exists_purge" value="ALTER
TABLE page_view DROP IF EXISTS PARTITION (dt='2008-08-08', country='us') PURGE"
db-types="Hive" />
+ <sql-case id="alter_table_drop_partition_if_exists_ignore_protection"
value="ALTER TABLE page_view DROP IF EXISTS PARTITION (dt='2008-08-08',
country='us') IGNORE PROTECTION" db-types="Hive" />
+ <sql-case id="alter_table_drop_multiple_partitions_if_exists_purge"
value="ALTER TABLE page_view DROP IF EXISTS PARTITION (dt='2008-08-08',
country='us'), PARTITION (dt='2008-08-09', country='cn') PURGE" db-types="Hive"
/>
+ <sql-case id="alter_table_drop_partition_all_options" value="ALTER TABLE
page_view DROP IF EXISTS PARTITION (dt='2008-08-08', country='us') IGNORE
PROTECTION PURGE" db-types="Hive" />
+ <sql-case id="alter_table_drop_multiple_partitions_all_options"
value="ALTER TABLE page_view DROP IF EXISTS PARTITION (dt='2008-08-08',
country='us'), PARTITION (dt='2008-08-09', country='cn') IGNORE PROTECTION
PURGE" db-types="Hive" />
+ <sql-case id="alter_table_archive_partition_basic" value="ALTER TABLE
log_table ARCHIVE PARTITION (dt='2025-07-25')" db-types="Hive" />
+ <sql-case id="alter_table_unarchive_partition_basic" value="ALTER TABLE
log_table UNARCHIVE PARTITION (dt='2025-07-25')" db-types="Hive" />
</sql-cases>