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 79a19e65260 Support import statement for mysql (#27207)
79a19e65260 is described below
commit 79a19e65260627970f218f82041fc0258fd08673
Author: niu niu <[email protected]>
AuthorDate: Sun Jul 16 14:08:19 2023 +0800
Support import statement for mysql (#27207)
---
.../src/main/antlr4/imports/mysql/DMLStatement.g4 | 2 +-
.../statement/type/MySQLDMLStatementVisitor.java | 7 ++++++
.../core/database/visitor/SQLVisitorRule.java | 2 ++
.../statement/mysql/dml/MySQLImportStatement.java | 28 ++++++++++++++++++++++
.../cases/parser/jaxb/RootSQLParserTestCases.java | 4 ++++
.../statement/dml/ImportStatementTestCase.java | 28 ++++++++++++++++++++++
.../parser/src/main/resources/case/dml/import.xml | 22 +++++++++++++++++
.../main/resources/sql/supported/dml/import.xml | 22 +++++++++++++++++
8 files changed, 114 insertions(+), 1 deletion(-)
diff --git
a/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/DMLStatement.g4
b/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/DMLStatement.g4
index d985983618e..37b063c8ea9 100644
--- a/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/DMLStatement.g4
+++ b/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/DMLStatement.g4
@@ -192,7 +192,7 @@ handlerCloseStatement
;
importStatement
- : IMPORT TABLE FROM string_ (COMMA_ string_)?
+ : IMPORT TABLE FROM textString (COMMA_ textString)?
;
loadStatement
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 c683a040f0d..bc4cb9a55a8 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
@@ -22,6 +22,7 @@ import
org.apache.shardingsphere.sql.parser.api.visitor.statement.type.DMLStatem
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.ImportStatementContext;
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;
@@ -31,6 +32,7 @@ import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.Sim
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.MySQLImportStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLLoadDataStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLLoadXMLStatement;
@@ -61,6 +63,11 @@ public final class MySQLDMLStatementVisitor extends
MySQLStatementVisitor implem
return new MySQLHandlerStatement();
}
+ @Override
+ public ASTNode visitImportStatement(final ImportStatementContext ctx) {
+ return new MySQLImportStatement();
+ }
+
@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 47d7f8e8f69..0a26b2a884f 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
@@ -467,6 +467,8 @@ public enum SQLVisitorRule {
CALL("Call", SQLStatementType.DML),
+ IMPORT_STATEMENT("ImportStatement", SQLStatementType.DML),
+
LOAD_STATEMENT("LoadStatement", SQLStatementType.DML),
CHANGE_MASTER("ChangeMaster", SQLStatementType.RL),
diff --git
a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/dml/MySQLImportStatement.java
b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/dml/MySQLImportStatement.java
new file mode 100644
index 00000000000..ad6f46ecbd9
--- /dev/null
+++
b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/dml/MySQLImportStatement.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 import statement.
+ */
+public final class MySQLImportStatement 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 d26e43c5145..c02f20b946f 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
@@ -285,6 +285,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.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.ImportStatementTestCase;
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;
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dml.LockTableStatementTestCase;
@@ -837,6 +838,9 @@ public final class RootSQLParserTestCases {
@XmlElement(name = "copy")
private final List<CopyStatementTestCase> copyTestCases = new
LinkedList<>();
+ @XmlElement(name = "import")
+ private final List<ImportStatementTestCase> importTestCase = new
LinkedList<>();
+
@XmlElement(name = "load-data")
private final List<LoadDataStatementTestCase> loadDataTestCases = new
LinkedList<>();
diff --git
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dml/ImportStatementTestCase.java
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dml/ImportStatementTestCase.java
new file mode 100644
index 00000000000..9028b6f6a6e
--- /dev/null
+++
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dml/ImportStatementTestCase.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;
+
+/**
+ * Import statement test case.
+ */
+@Getter
+public final class ImportStatementTestCase extends SQLParserTestCase {
+}
diff --git a/test/it/parser/src/main/resources/case/dml/import.xml
b/test/it/parser/src/main/resources/case/dml/import.xml
new file mode 100644
index 00000000000..c666b8d7ab0
--- /dev/null
+++ b/test/it/parser/src/main/resources/case/dml/import.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>
+ <import sql-case-id="import_table_from_file" />
+ <import sql-case-id="import_table_from_files" />
+</sql-parser-test-cases>
diff --git a/test/it/parser/src/main/resources/sql/supported/dml/import.xml
b/test/it/parser/src/main/resources/sql/supported/dml/import.xml
new file mode 100644
index 00000000000..c8e18ee67aa
--- /dev/null
+++ b/test/it/parser/src/main/resources/sql/supported/dml/import.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="import_table_from_file" value="IMPORT TABLE FROM
's1/t1*.sdi'" db-types="MySQL" />
+ <sql-case id="import_table_from_files" value="IMPORT TABLE FROM
'/tmp/mysql-files/employees.sdi','/tmp/mysql-files/managers.sdi'"
db-types="MySQL" />
+</sql-cases>