From 9dd553ede549a2b23368f39bad19764f3c03bcd6 Mon Sep 17 00:00:00 2001 From: JiaqiYan Date: Tue, 24 Oct 2023 20:06:37 +0800 Subject: [PATCH] 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 @@ + + + + + +