You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2025/07/11 05:46:21 UTC
(shardingsphere) branch master updated: fix:Support Hive DROP DATABASE statement parse (#35948)
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 38d9bcda0dc fix:Support Hive DROP DATABASE statement parse (#35948)
38d9bcda0dc is described below
commit 38d9bcda0dc2066a6ac3f01505abdfaadd5135e9
Author: Claire <cl...@163.com>
AuthorDate: Fri Jul 11 13:46:16 2025 +0800
fix:Support Hive DROP DATABASE statement parse (#35948)
* support Hive DROP DATABASE statement parse
* update RELEASE-NOTES
* resolve conflicts
---
RELEASE-NOTES.md | 4 ++--
.../hive/src/main/antlr4/imports/hive/DDLStatement.g4 | 8 ++++++++
.../shardingsphere/sql/parser/autogen/HiveStatement.g4 | 1 +
.../hive/visitor/statement/type/HiveDDLStatementVisitor.java | 8 ++++++++
test/it/parser/src/main/resources/case/ddl/drop-database.xml | 12 ++++++++++++
.../src/main/resources/sql/supported/ddl/drop-database.xml | 12 ++++++++++++
6 files changed, 43 insertions(+), 2 deletions(-)
diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md
index 7a7c961095e..f552bf1315e 100644
--- a/RELEASE-NOTES.md
+++ b/RELEASE-NOTES.md
@@ -50,10 +50,10 @@
1. SQL Parser: Support Oracle multiple backslash literal parsing - [#35784](https://github.com/apache/shardingsphere/pull/35784)
1. Proxy: Implement write method for PostgreSQL bool binary data type - [#35831](https://github.com/apache/shardingsphere/pull/35831)
1. SQL Binder: Add alter table metadata check - [#35877](https://github.com/apache/shardingsphere/pull/35877)
-1. SQL Parser: Support Hive CREATE DATABASE statment parse - [#35929](https://github.com/apache/shardingsphere/pull/35929)
+1. SQL Parser: Support Hive CREATE DATABASE statement parse - [#35929](https://github.com/apache/shardingsphere/pull/35929)
1. SQL Parser: Support sql parser extract unique index - [#35941](https://github.com/apache/shardingsphere/pull/35941)
1. SQL Parser: Support postgresql and opengauss create function with $$ symbol parse [#35947](https://github.com/apache/shardingsphere/pull/35947)
-
+1. SQL Parser: Support Hive DROP DATABASE statement parse - [#35948](https://github.com/apache/shardingsphere/pull/35948)
### Bug Fixes
1. Mode: Fixes issue of drop schema can not work on standalone mode - [#34470](https://github.com/apache/shardingsphere/pull/34470)
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 38f90d7e3c9..482afb5e5b4 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
@@ -23,6 +23,10 @@ createDatabase
: CREATE REMOTE? (DATABASE | SCHEMA) ifNotExists? identifier (COMMENT string_)? (LOCATION string_)? (MANAGEDLOCATION string_)? (WITH DBPROPERTIES LP_ dbProperties RP_)?
;
+dropDatabase
+ : DROP (DATABASE | SCHEMA) ifExists? identifier (RESTRICT | CASCADE)?
+ ;
+
ifNotExists
: IF NOT EXISTS
;
@@ -34,3 +38,7 @@ dbProperties
dbProperty
: string_ EQ_ string_
;
+
+ifExists
+ : IF EXISTS
+ ;
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 4525c2fe5d6..c862c1a6993 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
@@ -26,6 +26,7 @@ execute
| update
| delete
| createDatabase
+ | dropDatabase
) (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 91ed70f2d26..48569deb9d5 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
@@ -20,7 +20,9 @@ package org.apache.shardingsphere.sql.parser.hive.visitor.statement.type;
import org.apache.shardingsphere.sql.parser.api.visitor.statement.type.DDLStatementVisitor;
import org.apache.shardingsphere.sql.parser.hive.visitor.statement.HiveStatementVisitor;
import org.apache.shardingsphere.sql.parser.autogen.HiveStatementParser.CreateDatabaseContext;
+import org.apache.shardingsphere.sql.parser.autogen.HiveStatementParser.DropDatabaseContext;
import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.database.CreateDatabaseStatement;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.database.DropDatabaseStatement;
import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
import org.apache.shardingsphere.sql.parser.api.ASTNode;
@@ -34,4 +36,10 @@ public final class HiveDDLStatementVisitor extends HiveStatementVisitor implemen
return new CreateDatabaseStatement(new IdentifierValue(ctx.identifier().getText()).getValue(),
null != ctx.ifNotExists());
}
+
+ @Override
+ public ASTNode visitDropDatabase(final DropDatabaseContext ctx) {
+ return new DropDatabaseStatement(new IdentifierValue(ctx.identifier().getText()).getValue(),
+ null != ctx.ifExists());
+ }
}
diff --git a/test/it/parser/src/main/resources/case/ddl/drop-database.xml b/test/it/parser/src/main/resources/case/ddl/drop-database.xml
index f972ef04e08..25565dc6ff2 100644
--- a/test/it/parser/src/main/resources/case/ddl/drop-database.xml
+++ b/test/it/parser/src/main/resources/case/ddl/drop-database.xml
@@ -21,4 +21,16 @@
<drop-database sql-case-id="drop_database" />
<drop-database sql-case-id="drop_database_without_database_name" />
<drop-database sql-case-id="drop_database_including_backups_noprompt" />
+ <drop-database sql-case-id="drop_database_simple" />
+ <drop-database sql-case-id="drop_database_if_exists" />
+ <drop-database sql-case-id="drop_schema_simple" />
+ <drop-database sql-case-id="drop_schema_if_exists" />
+ <drop-database sql-case-id="drop_database_restrict" />
+ <drop-database sql-case-id="drop_schema_restrict" />
+ <drop-database sql-case-id="drop_database_cascade" />
+ <drop-database sql-case-id="drop_schema_cascade" />
+ <drop-database sql-case-id="drop_database_if_exists_restrict" />
+ <drop-database sql-case-id="drop_database_if_exists_cascade" />
+ <drop-database sql-case-id="drop_schema_if_exists_restrict" />
+ <drop-database sql-case-id="drop_schema_if_exists_cascade" />
</sql-parser-test-cases>
diff --git a/test/it/parser/src/main/resources/sql/supported/ddl/drop-database.xml b/test/it/parser/src/main/resources/sql/supported/ddl/drop-database.xml
index fa0daf98e39..06842aae135 100644
--- a/test/it/parser/src/main/resources/sql/supported/ddl/drop-database.xml
+++ b/test/it/parser/src/main/resources/sql/supported/ddl/drop-database.xml
@@ -21,4 +21,16 @@
<sql-case id="drop_database" value="DROP DATABASE database1" db-types="PostgreSQL,openGauss,SQLServer" />
<sql-case id="drop_database_without_database_name" value="DROP DATABASE" db-types="Oracle" />
<sql-case id="drop_database_including_backups_noprompt" value="DROP DATABASE INCLUDING BACKUPS NOPROMPT;" db-types="Oracle" />
+ <sql-case id="drop_database_simple" value="DROP DATABASE test_db" db-types="Hive" />
+ <sql-case id="drop_database_if_exists" value="DROP DATABASE IF EXISTS test_db" db-types="Hive" />
+ <sql-case id="drop_schema_simple" value="DROP SCHEMA test_schema" db-types="Hive" />
+ <sql-case id="drop_schema_if_exists" value="DROP SCHEMA IF EXISTS test_schema" db-types="Hive" />
+ <sql-case id="drop_database_restrict" value="DROP DATABASE test_db RESTRICT" db-types="Hive" />
+ <sql-case id="drop_schema_restrict" value="DROP SCHEMA test_schema RESTRICT" db-types="Hive" />
+ <sql-case id="drop_database_cascade" value="DROP DATABASE test_db CASCADE" db-types="Hive" />
+ <sql-case id="drop_schema_cascade" value="DROP SCHEMA test_schema CASCADE" db-types="Hive" />
+ <sql-case id="drop_database_if_exists_restrict" value="DROP DATABASE IF EXISTS test_db RESTRICT" db-types="Hive" />
+ <sql-case id="drop_database_if_exists_cascade" value="DROP DATABASE IF EXISTS test_db CASCADE" db-types="Hive" />
+ <sql-case id="drop_schema_if_exists_restrict" value="DROP SCHEMA IF EXISTS test_schema RESTRICT" db-types="Hive" />
+ <sql-case id="drop_schema_if_exists_cascade" value="DROP SCHEMA IF EXISTS test_schema CASCADE" db-types="Hive" />
</sql-cases>