Skip to content

Commit

Permalink
support Oracle switch SQL (#28855)
Browse files Browse the repository at this point in the history
* support Oracle switch SQL

* format code

* resolve conflict and format code
  • Loading branch information
chakkk309 authored Nov 6, 2023
1 parent 8ed5253 commit 55c71a6
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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?)
;
Expand Down Expand Up @@ -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_
;
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,6 @@ execute
| createJava
| plsqlBlock
| createLibrary
| switch
) SEMI_?
;
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
}
21 changes: 21 additions & 0 deletions test/it/parser/src/main/resources/case/ddl/switch.xml
Original file line number Diff line number Diff line change
@@ -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>
21 changes: 21 additions & 0 deletions test/it/parser/src/main/resources/sql/supported/ddl/switch.xml
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit 55c71a6

Please sign in to comment.