From 9dd553ede549a2b23368f39bad19764f3c03bcd6 Mon Sep 17 00:00:00 2001 From: JiaqiYan Date: Tue, 24 Oct 2023 20:06:37 +0800 Subject: [PATCH 1/3] support Oracle switch SQL --- .../antlr4/imports/oracle/DDLStatement.g4 | 14 ++++++++++ .../sql/parser/autogen/OracleStatement.g4 | 1 + .../type/OracleDDLStatementVisitor.java | 8 ++++++ .../core/database/visitor/SQLVisitorRule.java | 4 ++- .../oracle/ddl/OracleSwitchStatement.java | 27 +++++++++++++++++++ .../parser/jaxb/RootSQLParserTestCases.java | 4 +++ .../ddl/SwitchStatementTestCase.java | 26 ++++++++++++++++++ .../src/main/resources/case/ddl/switch.xml | 21 +++++++++++++++ .../resources/sql/supported/ddl/switch.xml | 21 +++++++++++++++ 9 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleSwitchStatement.java create mode 100644 test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ddl/SwitchStatementTestCase.java create mode 100644 test/it/parser/src/main/resources/case/ddl/switch.xml create mode 100644 test/it/parser/src/main/resources/sql/supported/ddl/switch.xml diff --git a/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/DDLStatement.g4 b/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/DDLStatement.g4 index beeacb52cb438..04abeb573de6c 100644 --- a/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/DDLStatement.g4 +++ b/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/DDLStatement.g4 @@ -4121,3 +4121,17 @@ fileType | CLOB | BLOB ; + +switch + : SWITCH switchClause TO COPY + ; + +switchClause + : DATABASE + | DATAFILE datafileSpecClause (COMMA_ datafileSpecClause)* + | TABLESPACE SQ_? tablespaceName SQ_? (COMMA_ SQ_? tablespaceName SQ_?)* + ; + +datafileSpecClause + : SQ_ fileName SQ_ | INTEGER_ + ; diff --git a/parser/sql/dialect/oracle/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/OracleStatement.g4 b/parser/sql/dialect/oracle/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/OracleStatement.g4 index 89ee86ff1abcf..b3efdd6cb9558 100644 --- a/parser/sql/dialect/oracle/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/OracleStatement.g4 +++ b/parser/sql/dialect/oracle/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/OracleStatement.g4 @@ -155,5 +155,6 @@ execute | createCluster | createJava | plsqlBlock + | switch ) SEMI_? ; diff --git a/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/type/OracleDDLStatementVisitor.java b/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/type/OracleDDLStatementVisitor.java index 31cdd381674ac..c70ea557f5cf3 100644 --- a/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/type/OracleDDLStatementVisitor.java +++ b/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/type/OracleDDLStatementVisitor.java @@ -140,6 +140,7 @@ import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.FlashbackDatabaseContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.FlashbackTableContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.FunctionContext; +import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.SwitchContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.IndexExpressionContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.IndexExpressionsContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.IndexNameContext; @@ -305,6 +306,7 @@ import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OraclePLSQLBlockStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OraclePurgeStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleRenameStatement; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleSwitchStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleSystemActionStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleTruncateStatement; @@ -1342,4 +1344,10 @@ public ASTNode visitAlterType(final AlterTypeContext ctx) { public ASTNode visitCreateJava(final CreateJavaContext ctx) { return new OracleCreateJavaStatement(); } + + @Override + public ASTNode visitSwitch(final SwitchContext ctx) { + return new OracleSwitchStatement(); + } + } 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 6fbab21d92425..44974836fc10e 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 @@ -697,8 +697,10 @@ public enum SQLVisitorRule { CREATE_JAVA("CreateJava", SQLStatementType.DDL), - PLSQL_BLOCK("PlsqlBlock", SQLStatementType.DDL); + PLSQL_BLOCK("PlsqlBlock", SQLStatementType.DDL), + SWITCH("Switch", SQLStatementType.DDL); + private final String name; @Getter diff --git a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleSwitchStatement.java b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleSwitchStatement.java new file mode 100644 index 0000000000000..f3461cd51fe37 --- /dev/null +++ b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleSwitchStatement.java @@ -0,0 +1,27 @@ +/* + * 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.oracle.ddl; + +import org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.OracleStatement; + +/** + * Oracle switch statement. + */ +public final class OracleSwitchStatement extends AbstractSQLStatement implements OracleStatement { +} 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 8900b7676ae06..ced25fa093d26 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 @@ -284,6 +284,7 @@ import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.RenameStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.RenameTableStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.SecurityLabelStmtStatementTestCase; +import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.SwitchStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.TruncateStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.UnlistenStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dml.CallStatementTestCase; @@ -1716,6 +1717,9 @@ public final class RootSQLParserTestCases { @XmlElement(name = "create-java") private final List createJavaStatementTestCases = new LinkedList<>(); + @XmlElement(name = "switch") + private final List switchStatementTestCases = new LinkedList<>(); + /** * Get all SQL parser test cases. * diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ddl/SwitchStatementTestCase.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ddl/SwitchStatementTestCase.java new file mode 100644 index 0000000000000..aac707e4c2288 --- /dev/null +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ddl/SwitchStatementTestCase.java @@ -0,0 +1,26 @@ +/* + * 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.ddl; + +import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.SQLParserTestCase; + +/** + * Switch statement test case. + */ +public final class SwitchStatementTestCase extends SQLParserTestCase { +} diff --git a/test/it/parser/src/main/resources/case/ddl/switch.xml b/test/it/parser/src/main/resources/case/ddl/switch.xml new file mode 100644 index 0000000000000..fc056b5378fdd --- /dev/null +++ b/test/it/parser/src/main/resources/case/ddl/switch.xml @@ -0,0 +1,21 @@ + + + + + + diff --git a/test/it/parser/src/main/resources/sql/supported/ddl/switch.xml b/test/it/parser/src/main/resources/sql/supported/ddl/switch.xml new file mode 100644 index 0000000000000..bff81e25b75c9 --- /dev/null +++ b/test/it/parser/src/main/resources/sql/supported/ddl/switch.xml @@ -0,0 +1,21 @@ + + + + + + From e3376cff6a5590b8b50c1b6debb9d2ca050db2ac Mon Sep 17 00:00:00 2001 From: JiaqiYan Date: Thu, 2 Nov 2023 20:37:15 +0800 Subject: [PATCH 2/3] format code --- .../visitor/statement/type/OracleDDLStatementVisitor.java | 4 ++-- .../sql/parser/core/database/visitor/SQLVisitorRule.java | 2 +- .../internal/cases/parser/jaxb/RootSQLParserTestCases.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/type/OracleDDLStatementVisitor.java b/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/type/OracleDDLStatementVisitor.java index c70ea557f5cf3..fb6b1293f158a 100644 --- a/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/type/OracleDDLStatementVisitor.java +++ b/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/type/OracleDDLStatementVisitor.java @@ -1344,10 +1344,10 @@ public ASTNode visitAlterType(final AlterTypeContext ctx) { public ASTNode visitCreateJava(final CreateJavaContext ctx) { return new OracleCreateJavaStatement(); } - + @Override public ASTNode visitSwitch(final SwitchContext ctx) { return new OracleSwitchStatement(); } - + } 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 44974836fc10e..473da5b6d3cf5 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 @@ -700,7 +700,7 @@ public enum SQLVisitorRule { PLSQL_BLOCK("PlsqlBlock", SQLStatementType.DDL), SWITCH("Switch", SQLStatementType.DDL); - + private final String name; @Getter 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 ced25fa093d26..67974bdb86a92 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 @@ -1719,7 +1719,7 @@ public final class RootSQLParserTestCases { @XmlElement(name = "switch") private final List switchStatementTestCases = new LinkedList<>(); - + /** * Get all SQL parser test cases. * From e0989119b24ca1452442c6bc33ee609f982f8b8c Mon Sep 17 00:00:00 2001 From: JiaqiYan Date: Sun, 5 Nov 2023 21:59:41 +0800 Subject: [PATCH 3/3] resolve conflict and format code --- .../visitor/statement/type/OracleDDLStatementVisitor.java | 6 +++--- .../sql/parser/core/database/visitor/SQLVisitorRule.java | 4 ++-- .../internal/cases/parser/jaxb/RootSQLParserTestCases.java | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/type/OracleDDLStatementVisitor.java b/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/type/OracleDDLStatementVisitor.java index a2a2a0b5b837f..cb73231cb424a 100644 --- a/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/type/OracleDDLStatementVisitor.java +++ b/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/type/OracleDDLStatementVisitor.java @@ -1346,15 +1346,15 @@ public ASTNode visitAlterType(final AlterTypeContext ctx) { public ASTNode visitCreateJava(final CreateJavaContext ctx) { return new OracleCreateJavaStatement(); } - + @Override public ASTNode visitCreateLibrary(final CreateLibraryContext ctx) { return new OracleCreateLibraryStatement(); } - + @Override public ASTNode visitSwitch(final SwitchContext ctx) { return new OracleSwitchStatement(); } - + } 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 e0ed72dffc8de..465ee7edd0d3c 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 @@ -698,9 +698,9 @@ public enum SQLVisitorRule { CREATE_JAVA("CreateJava", SQLStatementType.DDL), PLSQL_BLOCK("PlsqlBlock", SQLStatementType.DDL), - + CREATE_LIBRARY("CreateLibrary", SQLStatementType.DDL), - + SWITCH("Switch", SQLStatementType.DDL); private final String name; 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 1025ee2f174e8..773671e976736 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 @@ -1720,10 +1720,10 @@ public final class RootSQLParserTestCases { @XmlElement(name = "create-library") private final List createLibraryStatementTestCases = new LinkedList<>(); - + @XmlElement(name = "switch") private final List switchStatementTestCases = new LinkedList<>(); - + /** * Get all SQL parser test cases. *