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 9df2ba647d6 Support handler statement for mysql (#26723)
9df2ba647d6 is described below

commit 9df2ba647d6f747c8e6ab36be99186aa90627905
Author: niu niu <[email protected]>
AuthorDate: Sat Jul 1 11:16:14 2023 +0800

    Support handler statement for mysql (#26723)
    
    * Support handler statement for mysql
    
    * Add test sql
---
 .../statement/type/MySQLDMLStatementVisitor.java   |  7 ++++++
 .../core/database/visitor/SQLVisitorRule.java      |  2 ++
 .../statement/mysql/dml/MySQLHandlerStatement.java | 28 ++++++++++++++++++++++
 .../cases/parser/jaxb/RootSQLParserTestCases.java  |  4 ++++
 .../statement/dml/HandlerStatementTestCase.java    | 28 ++++++++++++++++++++++
 .../parser/src/main/resources/case/dml/handler.xml | 22 +++++++++++++++++
 .../main/resources/sql/supported/dml/handler.xml   | 22 +++++++++++++++++
 7 files changed, 113 insertions(+)

diff --git 
a/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/type/MySQLDMLStatementVisitor.java
 
b/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/type/MySQLDMLStatementVisitor.java
index acc55bb4a44..c683a040f0d 100644
--- 
a/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/type/MySQLDMLStatementVisitor.java
+++ 
b/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/type/MySQLDMLStatementVisitor.java
@@ -21,6 +21,7 @@ import org.apache.shardingsphere.sql.parser.api.ASTNode;
 import 
org.apache.shardingsphere.sql.parser.api.visitor.statement.type.DMLStatementVisitor;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.CallContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.DoStatementContext;
+import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.HandlerStatementContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.LoadDataStatementContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.LoadStatementContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.LoadXmlStatementContext;
@@ -29,6 +30,7 @@ import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.Expressi
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLCallStatement;
 import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLDoStatement;
+import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLHandlerStatement;
 import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLLoadDataStatement;
 import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLLoadXMLStatement;
 
@@ -54,6 +56,11 @@ public final class MySQLDMLStatementVisitor extends 
MySQLStatementVisitor implem
         return new MySQLDoStatement(params);
     }
     
+    @Override
+    public ASTNode visitHandlerStatement(final HandlerStatementContext ctx) {
+        return new MySQLHandlerStatement();
+    }
+    
     @Override
     public ASTNode visitLoadStatement(final LoadStatementContext ctx) {
         return null != ctx.loadDataStatement() ? 
visit(ctx.loadDataStatement()) : visit(ctx.loadXmlStatement());
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 38b719c9e00..794ba004b89 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
@@ -45,6 +45,8 @@ public enum SQLVisitorRule {
     
     COPY("Copy", SQLStatementType.DML),
     
+    HANDLER_STATEMENT("HandlerStatement", SQLStatementType.DML),
+    
     LOCKTABLE("LockTable", SQLStatementType.DML),
     
     CREATE_TABLE("CreateTable", SQLStatementType.DDL),
diff --git 
a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/dml/MySQLHandlerStatement.java
 
b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/dml/MySQLHandlerStatement.java
new file mode 100644
index 00000000000..ac49b604fea
--- /dev/null
+++ 
b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/dml/MySQLHandlerStatement.java
@@ -0,0 +1,28 @@
+/*
+ * 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.sql.dialect.statement.mysql.dml;
+
+import 
org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement;
+import 
org.apache.shardingsphere.sql.parser.sql.common.statement.dml.DMLStatement;
+import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.MySQLStatement;
+
+/**
+ * MySQL handler statement.
+ */
+public final class MySQLHandlerStatement extends AbstractSQLStatement 
implements DMLStatement, MySQLStatement {
+}
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 251af9c4fcc..5f2cae3eaed 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
@@ -282,6 +282,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.dml.CopyStatementTestCase;
 import 
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dml.DeleteStatementTestCase;
 import 
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dml.DoStatementTestCase;
+import 
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dml.HandlerStatementTestCase;
 import 
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dml.InsertStatementTestCase;
 import 
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dml.LoadDataStatementTestCase;
 import 
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dml.LoadXMLStatementTestCase;
@@ -829,6 +830,9 @@ public final class RootSQLParserTestCases {
     @XmlElement(name = "do")
     private final List<DoStatementTestCase> doTestCases = new LinkedList<>();
     
+    @XmlElement(name = "handler")
+    private final List<HandlerStatementTestCase> handlerStatementTestCases = 
new LinkedList<>();
+    
     @XmlElement(name = "copy")
     private final List<CopyStatementTestCase> copyTestCases = new 
LinkedList<>();
     
diff --git 
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dml/HandlerStatementTestCase.java
 
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dml/HandlerStatementTestCase.java
new file mode 100644
index 00000000000..43523734511
--- /dev/null
+++ 
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dml/HandlerStatementTestCase.java
@@ -0,0 +1,28 @@
+/*
+ * 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.test.it.sql.parser.internal.cases.parser.jaxb.statement.dml;
+
+import lombok.Getter;
+import 
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.SQLParserTestCase;
+
+/**
+ * Handler statement test case.
+ */
+@Getter
+public final class HandlerStatementTestCase extends SQLParserTestCase {
+}
diff --git a/test/it/parser/src/main/resources/case/dml/handler.xml 
b/test/it/parser/src/main/resources/case/dml/handler.xml
new file mode 100644
index 00000000000..429da3dc6b1
--- /dev/null
+++ b/test/it/parser/src/main/resources/case/dml/handler.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>
+    <handler sql-case-id="handler_table_name_with_close" />
+    <handler sql-case-id="handler_table_name_read_limit" />
+</sql-parser-test-cases>
diff --git a/test/it/parser/src/main/resources/sql/supported/dml/handler.xml 
b/test/it/parser/src/main/resources/sql/supported/dml/handler.xml
new file mode 100644
index 00000000000..b83d597e1db
--- /dev/null
+++ b/test/it/parser/src/main/resources/sql/supported/dml/handler.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="handler_table_name_with_close" value="HANDLER t1 CLOSE" 
db-types="MySQL" />
+    <sql-case id="handler_table_name_read_limit" value="handler a1 read first 
limit 9" db-types="MySQL" />
+</sql-cases>

Reply via email to