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 3cc31d6bfde fix:Support Hive DROP MACRO statement parse (#36187) 3cc31d6bfde is described below commit 3cc31d6bfdee9cdf20050f228a224c55c8c002e3 Author: Claire <claire040...@163.com> AuthorDate: Tue Aug 5 18:49:52 2025 +0800 fix:Support Hive DROP MACRO statement parse (#36187) * support hive drop macro statement * update RELEASE-NOTES --- RELEASE-NOTES.md | 1 + .../src/main/antlr4/imports/hive/DDLStatement.g4 | 4 ++ .../sql/parser/autogen/HiveStatement.g4 | 1 + .../statement/type/HiveDDLStatementVisitor.java | 7 ++++ .../core/database/visitor/SQLVisitorRule.java | 2 + .../type/ddl/macro/DropMacroStatement.java} | 43 ++++++---------------- .../cases/parser/jaxb/RootSQLParserTestCases.java | 4 ++ .../standard/macro/DropMacroStatementTestCase.java | 38 ++++--------------- .../src/main/resources/case/ddl/drop-macro.xml | 22 +++++++++++ .../resources/sql/supported/ddl/drop-macro.xml | 22 +++++++++++ 10 files changed, 82 insertions(+), 62 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 3ec91abc51f..f1057a0114f 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -70,6 +70,7 @@ 1. SQL Parser: Support Hive DROP INDEX statement parse - [#36166](https://github.com/apache/shardingsphere/pull/36166) 1. SQL Parser: Support Hive ALTER INDEX statement parse - [#36167](https://github.com/apache/shardingsphere/pull/36167) 1. SQL Parser: Support Hive CREATE MACRO statement parse - [#36181](https://github.com/apache/shardingsphere/pull/36181) +1. SQL Parser: Support Hive DROP MACRO statement parse - [#36187](https://github.com/apache/shardingsphere/pull/36187) 1. SQL Parser: Support SQL Server xml methods parse - [#35911](https://github.com/apache/shardingsphere/pull/35911) 1. SQL Parser: Support SQL Server CHANGETABLE function parse - [#35920](https://github.com/apache/shardingsphere/pull/35920) 1. SQL Parser: Support SQL Server AI_GENERATE_EMBEDDINGS function parse - [#35922](https://github.com/apache/shardingsphere/pull/35922) 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 9ae591b5f6e..313b72fa425 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 @@ -120,6 +120,10 @@ createMacro : CREATE TEMPORARY MACRO macroName LP_ macroParameterList? RP_ expr ; +dropMacro + : DROP TEMPORARY MACRO ifExists? macroName + ; + 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 85d96cd8201..c1e3df8c739 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 @@ -45,6 +45,7 @@ execute | dropIndex | alterIndex | createMacro + | dropMacro ) (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 b19ae6e3328..b20fca1f626 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 @@ -46,6 +46,7 @@ import org.apache.shardingsphere.sql.parser.autogen.HiveStatementParser.CreateIn import org.apache.shardingsphere.sql.parser.autogen.HiveStatementParser.DropIndexContext; import org.apache.shardingsphere.sql.parser.autogen.HiveStatementParser.AlterIndexContext; import org.apache.shardingsphere.sql.parser.autogen.HiveStatementParser.CreateMacroContext; +import org.apache.shardingsphere.sql.parser.autogen.HiveStatementParser.DropMacroContext; 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; @@ -72,6 +73,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.vi import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.view.DropMaterializedViewStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.view.AlterMaterializedViewStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.macro.CreateMacroStatement; +import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.macro.DropMacroStatement; 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; @@ -404,4 +406,9 @@ public final class HiveDDLStatementVisitor extends HiveStatementVisitor implemen public ASTNode visitCreateMacro(final CreateMacroContext ctx) { return new CreateMacroStatement(getDatabaseType()); } + + @Override + public ASTNode visitDropMacro(final DropMacroContext ctx) { + return new DropMacroStatement(getDatabaseType()); + } } 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 66a06850a09..6748e1886a1 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 @@ -671,6 +671,8 @@ public enum SQLVisitorRule { CREATE_MACRO("CreateMacro", SQLStatementType.DDL), + DROP_MACRO("DropMacro", SQLStatementType.DDL), + CREATE_MATERIALIZED_VIEW_LOG("CreateMaterializedViewLog", SQLStatementType.DDL), CREATE_OPERATOR("CreateOperator", SQLStatementType.DDL), diff --git a/parser/sql/dialect/hive/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/HiveStatement.g4 b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/ddl/macro/DropMacroStatement.java similarity index 56% copy from parser/sql/dialect/hive/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/HiveStatement.g4 copy to parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/ddl/macro/DropMacroStatement.java index 85d96cd8201..f1615b2fcc0 100644 --- a/parser/sql/dialect/hive/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/HiveStatement.g4 +++ b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/ddl/macro/DropMacroStatement.java @@ -15,36 +15,17 @@ * limitations under the License. */ -grammar HiveStatement; +package org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.macro; -import Comments, DMLStatement, DDLStatement; +import org.apache.shardingsphere.infra.database.core.type.DatabaseType; +import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.DDLStatement; -// TODO correct hive SQL parsing according to official documentation -execute - : (select - | insert - | update - | delete - | loadStatement - | createDatabase - | dropDatabase - | alterDatabase - | use - | createTable - | dropTable - | truncateTable - | msckStatement - | alterTable - | createView - | dropView - | alterView - | createMaterializedView - | dropMaterializedView - | alterMaterializedView - | createIndex - | dropIndex - | alterIndex - | createMacro - ) (SEMI_ EOF? | EOF) - | EOF - ; +/** + * Drop macro statement. + */ +public final class DropMacroStatement extends DDLStatement { + + public DropMacroStatement(final DatabaseType databaseType) { + super(databaseType); + } +} diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/RootSQLParserTestCases.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/RootSQLParserTestCases.java index 65f1c974bf4..e2b1cc418ba 100644 --- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/RootSQLParserTestCases.java +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/RootSQLParserTestCases.java @@ -260,6 +260,7 @@ import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.s import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.standard.index.CreateIndexStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.standard.index.DropIndexStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.standard.macro.CreateMacroStatementTestCase; +import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.standard.macro.DropMacroStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.standard.operator.AlterOperatorStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.standard.operator.CreateOperatorStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.standard.operator.DropOperatorStatementTestCase; @@ -1756,6 +1757,9 @@ public final class RootSQLParserTestCases { @XmlElement(name = "create-macro") private final List<CreateMacroStatementTestCase> createMacroTestCases = new LinkedList<>(); + @XmlElement(name = "drop-macro") + private final List<DropMacroStatementTestCase> dropMacroTestCases = new LinkedList<>(); + /** * Get all SQL parser test cases. * diff --git a/parser/sql/dialect/hive/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/HiveStatement.g4 b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ddl/standard/macro/DropMacroStatementTestCase.java similarity index 56% copy from parser/sql/dialect/hive/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/HiveStatement.g4 copy to test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ddl/standard/macro/DropMacroStatementTestCase.java index 85d96cd8201..9a7fb13804d 100644 --- a/parser/sql/dialect/hive/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/HiveStatement.g4 +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ddl/standard/macro/DropMacroStatementTestCase.java @@ -15,36 +15,12 @@ * limitations under the License. */ -grammar HiveStatement; +package org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.standard.macro; -import Comments, DMLStatement, DDLStatement; +import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.SQLParserTestCase; -// TODO correct hive SQL parsing according to official documentation -execute - : (select - | insert - | update - | delete - | loadStatement - | createDatabase - | dropDatabase - | alterDatabase - | use - | createTable - | dropTable - | truncateTable - | msckStatement - | alterTable - | createView - | dropView - | alterView - | createMaterializedView - | dropMaterializedView - | alterMaterializedView - | createIndex - | dropIndex - | alterIndex - | createMacro - ) (SEMI_ EOF? | EOF) - | EOF - ; +/** + * Drop macro statement test case. + */ +public final class DropMacroStatementTestCase extends SQLParserTestCase { +} diff --git a/test/it/parser/src/main/resources/case/ddl/drop-macro.xml b/test/it/parser/src/main/resources/case/ddl/drop-macro.xml new file mode 100644 index 00000000000..a5ce46aa930 --- /dev/null +++ b/test/it/parser/src/main/resources/case/ddl/drop-macro.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one or more + ~ contributor license agreements. See the NOTICE file distributed with + ~ this work for additional information regarding copyright ownership. + ~ The ASF licenses this file to You under the Apache License, Version 2.0 + ~ (the "License"); you may not use this file except in compliance with + ~ the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> + +<sql-parser-test-cases> + <drop-macro sql-case-id="drop_temp_macro_basic" /> + <drop-macro sql-case-id="drop_temp_macro_with_if_exists" /> +</sql-parser-test-cases> diff --git a/test/it/parser/src/main/resources/sql/supported/ddl/drop-macro.xml b/test/it/parser/src/main/resources/sql/supported/ddl/drop-macro.xml new file mode 100644 index 00000000000..b2afa162d70 --- /dev/null +++ b/test/it/parser/src/main/resources/sql/supported/ddl/drop-macro.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one or more + ~ contributor license agreements. See the NOTICE file distributed with + ~ this work for additional information regarding copyright ownership. + ~ The ASF licenses this file to You under the Apache License, Version 2.0 + ~ (the "License"); you may not use this file except in compliance with + ~ the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> + +<sql-cases> + <sql-case id="drop_temp_macro_basic" value="DROP TEMPORARY MACRO simple_add;" db-types="Hive" /> + <sql-case id="drop_temp_macro_with_if_exists" value="DROP TEMPORARY MACRO IF EXISTS string_len;" db-types="Hive" /> +</sql-cases>