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 55c71a6d4d8 support Oracle switch SQL (#28855)
55c71a6d4d8 is described below
commit 55c71a6d4d8714b21d4b0e0e4eccac41657537f3
Author: +7 <[email protected]>
AuthorDate: Mon Nov 6 08:11:53 2023 +0800
support Oracle switch SQL (#28855)
* support Oracle switch SQL
* format code
* resolve conflict and format code
---
.../src/main/antlr4/imports/oracle/DDLStatement.g4 | 16 ++++++++++++-
.../sql/parser/autogen/OracleStatement.g4 | 1 +
.../statement/type/OracleDDLStatementVisitor.java | 8 +++++++
.../core/database/visitor/SQLVisitorRule.java | 4 +++-
.../oracle/ddl/OracleSwitchStatement.java | 27 ++++++++++++++++++++++
.../cases/parser/jaxb/RootSQLParserTestCases.java | 4 ++++
.../statement/ddl/SwitchStatementTestCase.java | 26 +++++++++++++++++++++
.../parser/src/main/resources/case/ddl/switch.xml | 21 +++++++++++++++++
.../main/resources/sql/supported/ddl/switch.xml | 21 +++++++++++++++++
9 files changed, 126 insertions(+), 2 deletions(-)
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 cbedb007733..6ad7c8a8d82 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 5066afe35ac..f6b97c85eb0 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 ab47e143b64..cb73231cb42 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.DropVi
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.Ora
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 final class OracleDDLStatementVisitor extends
OracleStatementVisitor impl
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 1fcaa758edf..465ee7edd0d 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 00000000000..f3461cd51fe
--- /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 ad4863f610d..773671e9767 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.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<CreateLibraryStatementTestCase>
createLibraryStatementTestCases = new LinkedList<>();
+ @XmlElement(name = "switch")
+ private final List<SwitchStatementTestCase> 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 00000000000..aac707e4c22
--- /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 00000000000..fc056b5378f
--- /dev/null
+++ b/test/it/parser/src/main/resources/case/ddl/switch.xml
@@ -0,0 +1,21 @@
+<?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>
+ <switch sql-case-id="switch" />
+</sql-parser-test-cases>
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 00000000000..bff81e25b75
--- /dev/null
+++ b/test/it/parser/src/main/resources/sql/supported/ddl/switch.xml
@@ -0,0 +1,21 @@
+<?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="switch" value="SWITCH DATABASE TO COPY;" db-types="Oracle" />
+</sql-cases>