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 cbedb007733c6..6ad7c8a8d82c6 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 @@ -4010,7 +4010,7 @@ tablespaceFileNameConvert ; alterTablespaceEncryption - : ENCRYPTION(OFFLINE (tablespaceEncryptionSpec? ENCRYPT | DECRYPT) + : ENCRYPTION(OFFLINE (tablespaceEncryptionSpec? ENCRYPT | DECRYPT) | ONLINE (tablespaceEncryptionSpec? (ENCRYPT | REKEY) | DECRYPT) tablespaceFileNameConvert? | FINISH (ENCRYPT | REKEY | DECRYPT) tablespaceFileNameConvert?) ; @@ -4126,3 +4126,17 @@ plsqlLibrarySource agentClause : (AGENT agentDblink)? (CREDENTIAL credentialName)? ; + +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 5066afe35acdc..f6b97c85eb034 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 @@ -156,5 +156,6 @@ execute | createJava | plsqlBlock | createLibrary + | 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 ab47e143b642d..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 @@ -141,6 +141,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; @@ -307,6 +308,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; @@ -1349,4 +1351,10 @@ public ASTNode visitCreateJava(final CreateJavaContext ctx) { 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 1fcaa758edf48..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 @@ -699,7 +699,9 @@ public enum SQLVisitorRule { PLSQL_BLOCK("PlsqlBlock", SQLStatementType.DDL), - CREATE_LIBRARY("CreateLibrary", SQLStatementType.DDL); + CREATE_LIBRARY("CreateLibrary", SQLStatementType.DDL), + + SWITCH("Switch", SQLStatementType.DDL); private final String name; 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 ad4863f610d07..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 @@ -285,6 +285,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; @@ -1720,6 +1721,9 @@ 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. * 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 @@ + + + + + +