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 7a7d27f0401 Support Hive ABORT statement parse (#36378)
7a7d27f0401 is described below
commit 7a7d27f040100c62d7f0aa11806ccb39ad16a3ae
Author: Claire <[email protected]>
AuthorDate: Thu Aug 21 15:43:50 2025 +0800
Support Hive ABORT statement parse (#36378)
* support abort statement
* UPDATE RELEASE-NOTES
* Update HiveStatement.g4
---
RELEASE-NOTES.md | 1 +
.../src/main/antlr4/imports/hive/HiveKeyword.g4 | 4 ++
.../hive/TCLStatement.g4} | 40 ++----------------
.../sql/parser/autogen/HiveStatement.g4 | 3 +-
.../statement/HiveStatementVisitorFacade.java | 3 +-
.../statement/type/HiveTCLStatementVisitor.java | 40 ++++++++++++++++++
.../statement/hive/tcl/HiveAbortStatement.java} | 49 ++++++----------------
.../cases/parser/jaxb/RootSQLParserTestCases.java | 4 ++
.../statement/tcl/HiveAbortStatementTestCase.java | 44 ++++---------------
.../parser/src/main/resources/case/tcl/abort.xml | 22 ++++++++++
.../src/main/resources/sql/supported/tcl/abort.xml | 22 ++++++++++
11 files changed, 120 insertions(+), 112 deletions(-)
diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md
index 6f9d6343ebb..92b00a1cab3 100644
--- a/RELEASE-NOTES.md
+++ b/RELEASE-NOTES.md
@@ -81,6 +81,7 @@
1. SQL Parser: Support Hive Show Granted Roles and Privileges & SHOW LOCKS &
SHOW CONF statement parse -
[#36300](https://github.com/apache/shardingsphere/pull/36300)
1. SQL Parser: Support Hive SHOW TRANSACTIONS & SHOW COMPACTIONS statement
parse - [#36301](https://github.com/apache/shardingsphere/pull/36301)
1. SQL Parser: Support Hive DESCRIBE statement parse -
[#36350](https://github.com/apache/shardingsphere/pull/36350)
+1. SQL Parser: Support Hive ABORT statement parse -
[#36378](https://github.com/apache/shardingsphere/pull/36378)
1. SQL Parser: Support Hive Inserting data into Hive Tables from queries
statement parse - [#36320](https://github.com/apache/shardingsphere/pull/36320)
1. SQL Parser: Support Hive Writing data into the filesystem from queries
statement parse - [#36371](https://github.com/apache/shardingsphere/pull/36371)
1. SQL Parser: Support SQL Server xml methods parse -
[#35911](https://github.com/apache/shardingsphere/pull/35911)
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 56c899cdaf6..bd262ba7016 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
@@ -3409,3 +3409,7 @@ STATE
COMPACTIONID
: C O M P A C T I O N I D
;
+
+ABORT
+ : A B O R T
+ ;
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/imports/hive/TCLStatement.g4
similarity index 52%
copy from
parser/sql/dialect/hive/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/HiveStatement.g4
copy to parser/sql/dialect/hive/src/main/antlr4/imports/hive/TCLStatement.g4
index 69a72b1d51a..6e719e0495f 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/imports/hive/TCLStatement.g4
@@ -15,42 +15,10 @@
* limitations under the License.
*/
-grammar HiveStatement;
+grammar TCLStatement;
-import Comments, DMLStatement, DDLStatement, DALStatement;
+import BaseRule;
-// 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
- | dropMacro
- | createFunction
- | dropFunction
- | reloadFunction
- | show
- | describe
- ) (SEMI_ EOF? | EOF)
- | EOF
+abort
+ : ABORT TRANSACTIONS NUMBER_+
;
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 69a72b1d51a..c1231e6585e 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
@@ -17,7 +17,7 @@
grammar HiveStatement;
-import Comments, DMLStatement, DDLStatement, DALStatement;
+import Comments, DMLStatement, DDLStatement, DALStatement, TCLStatement;
// TODO correct hive SQL parsing according to official documentation
execute
@@ -51,6 +51,7 @@ execute
| reloadFunction
| show
| describe
+ | abort
) (SEMI_ EOF? | EOF)
| EOF
;
diff --git
a/parser/sql/dialect/hive/src/main/java/org/apache/shardingsphere/sql/parser/hive/visitor/statement/HiveStatementVisitorFacade.java
b/parser/sql/dialect/hive/src/main/java/org/apache/shardingsphere/sql/parser/hive/visitor/statement/HiveStatementVisitorFacade.java
index 3fc621bd3cc..34529b24bb4 100644
---
a/parser/sql/dialect/hive/src/main/java/org/apache/shardingsphere/sql/parser/hive/visitor/statement/HiveStatementVisitorFacade.java
+++
b/parser/sql/dialect/hive/src/main/java/org/apache/shardingsphere/sql/parser/hive/visitor/statement/HiveStatementVisitorFacade.java
@@ -26,6 +26,7 @@ import
org.apache.shardingsphere.sql.parser.api.visitor.statement.type.TCLStatem
import
org.apache.shardingsphere.sql.parser.hive.visitor.statement.type.HiveDALStatementVisitor;
import
org.apache.shardingsphere.sql.parser.hive.visitor.statement.type.HiveDDLStatementVisitor;
import
org.apache.shardingsphere.sql.parser.hive.visitor.statement.type.HiveDMLStatementVisitor;
+import
org.apache.shardingsphere.sql.parser.hive.visitor.statement.type.HiveTCLStatementVisitor;
import org.apache.shardingsphere.sql.parser.spi.SQLStatementVisitorFacade;
/**
@@ -45,7 +46,7 @@ public final class HiveStatementVisitorFacade implements
SQLStatementVisitorFaca
@Override
public Class<? extends TCLStatementVisitor> getTCLVisitorClass() {
- throw new UnsupportedOperationException("");
+ return HiveTCLStatementVisitor.class;
}
@Override
diff --git
a/parser/sql/dialect/hive/src/main/java/org/apache/shardingsphere/sql/parser/hive/visitor/statement/type/HiveTCLStatementVisitor.java
b/parser/sql/dialect/hive/src/main/java/org/apache/shardingsphere/sql/parser/hive/visitor/statement/type/HiveTCLStatementVisitor.java
new file mode 100644
index 00000000000..332286b75e0
--- /dev/null
+++
b/parser/sql/dialect/hive/src/main/java/org/apache/shardingsphere/sql/parser/hive/visitor/statement/type/HiveTCLStatementVisitor.java
@@ -0,0 +1,40 @@
+/*
+ * 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.
+ */
+
+package org.apache.shardingsphere.sql.parser.hive.visitor.statement.type;
+
+import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
+import org.apache.shardingsphere.sql.parser.api.ASTNode;
+import
org.apache.shardingsphere.sql.parser.api.visitor.statement.type.TCLStatementVisitor;
+import
org.apache.shardingsphere.sql.parser.autogen.HiveStatementParser.AbortContext;
+import
org.apache.shardingsphere.sql.parser.hive.visitor.statement.HiveStatementVisitor;
+import
org.apache.shardingsphere.sql.parser.statement.hive.tcl.HiveAbortStatement;
+
+/**
+ * TCL statement visitor for Hive.
+ */
+public final class HiveTCLStatementVisitor extends HiveStatementVisitor
implements TCLStatementVisitor {
+
+ public HiveTCLStatementVisitor(final DatabaseType databaseType) {
+ super(databaseType);
+ }
+
+ @Override
+ public ASTNode visitAbort(final AbortContext ctx) {
+ return new HiveAbortStatement(getDatabaseType());
+ }
+}
diff --git
a/parser/sql/dialect/hive/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/HiveStatement.g4
b/parser/sql/statement/type/hive/src/main/java/org/apache/shardingsphere/sql/parser/statement/hive/tcl/HiveAbortStatement.java
similarity index 52%
copy from
parser/sql/dialect/hive/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/HiveStatement.g4
copy to
parser/sql/statement/type/hive/src/main/java/org/apache/shardingsphere/sql/parser/statement/hive/tcl/HiveAbortStatement.java
index 69a72b1d51a..6f1c9dc0b2f 100644
---
a/parser/sql/dialect/hive/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/HiveStatement.g4
+++
b/parser/sql/statement/type/hive/src/main/java/org/apache/shardingsphere/sql/parser/statement/hive/tcl/HiveAbortStatement.java
@@ -15,42 +15,17 @@
* limitations under the License.
*/
-grammar HiveStatement;
+package org.apache.shardingsphere.sql.parser.statement.hive.tcl;
-import Comments, DMLStatement, DDLStatement, DALStatement;
+import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
+import
org.apache.shardingsphere.sql.parser.statement.core.statement.type.dal.DALStatement;
-// 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
- | dropMacro
- | createFunction
- | dropFunction
- | reloadFunction
- | show
- | describe
- ) (SEMI_ EOF? | EOF)
- | EOF
- ;
+/**
+ * Hive abort statement.
+ */
+public final class HiveAbortStatement extends DALStatement {
+
+ public HiveAbortStatement(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 f439de63bc6..d772b898893 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
@@ -21,6 +21,7 @@ import com.google.common.base.Preconditions;
import lombok.Getter;
import lombok.SneakyThrows;
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.CommonStatementTestCase;
+import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.tcl.HiveAbortStatementTestCase;
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.dialect.mysql.MySQLCloneStatementTestCase;
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.dialect.mysql.MySQLCreateLoadableFunctionTestCase;
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.dialect.mysql.MySQLDelimiterStatementTestCase;
@@ -1764,6 +1765,9 @@ public final class RootSQLParserTestCases {
@XmlElement(name = "reload-function")
private final List<ReloadFunctionStatementTestCase>
reloadFunctionStatementTestCases = new LinkedList<>();
+ @XmlElement(name = "abort")
+ private final List<HiveAbortStatementTestCase> hiveAbortStatementTestCase
= 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/tcl/HiveAbortStatementTestCase.java
similarity index 52%
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/tcl/HiveAbortStatementTestCase.java
index 69a72b1d51a..468629bfc6f 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/tcl/HiveAbortStatementTestCase.java
@@ -15,42 +15,12 @@
* limitations under the License.
*/
-grammar HiveStatement;
+package
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.tcl;
-import Comments, DMLStatement, DDLStatement, DALStatement;
+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
- | dropMacro
- | createFunction
- | dropFunction
- | reloadFunction
- | show
- | describe
- ) (SEMI_ EOF? | EOF)
- | EOF
- ;
+/**
+ * Hive abort statement test case.
+ */
+public final class HiveAbortStatementTestCase extends SQLParserTestCase {
+}
diff --git a/test/it/parser/src/main/resources/case/tcl/abort.xml
b/test/it/parser/src/main/resources/case/tcl/abort.xml
new file mode 100644
index 00000000000..5faf56f55de
--- /dev/null
+++ b/test/it/parser/src/main/resources/case/tcl/abort.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>
+ <abort sql-case-id="abort_transactionID" />
+ <abort sql-case-id="abort_more_transactionID" />
+</sql-parser-test-cases>
diff --git a/test/it/parser/src/main/resources/sql/supported/tcl/abort.xml
b/test/it/parser/src/main/resources/sql/supported/tcl/abort.xml
new file mode 100644
index 00000000000..10bf457f700
--- /dev/null
+++ b/test/it/parser/src/main/resources/sql/supported/tcl/abort.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="abort_transactionID" value="ABORT TRANSACTIONS 0000007"
db-types="Hive" />
+ <sql-case id="abort_more_transactionID" value="ABORT TRANSACTIONS 0000007
0000008 0000010 0000015" db-types="Hive" />
+</sql-cases>