From 15ee3e3a87d9241ccd8ae0042085c4e506d4b8b0 Mon Sep 17 00:00:00 2001 From: tianhao960 Date: Wed, 24 Aug 2022 08:59:08 +0800 Subject: [PATCH] add alter and drop procedure statement for oracle (#20463) * add createProcedure rule for oracle #1 * add createProcedure rule for oracle #2 * add createProcedure rule for oracle #3 * add createProcedure rule for oracle #4 * add createProcedure rule for oracle #5 * add createProcedure rule for oracle #6 * add createProcedure rule for oracle #6 * add createProcedure rule for oracle #7 * add dropProcedure and alterProcedure rule for oracle * add javadoc and final for ProcedureStatement --- .../antlr4/imports/oracle/StoreProcedure.g4 | 68 ++++++++++++------- .../sql/parser/autogen/OracleStatement.g4 | 2 + .../impl/OracleDDLStatementSQLVisitor.java | 14 ++++ .../ddl/OracleAlterProcedureStatement.java | 29 ++++++++ .../ddl/OracleCreateProcedureStatement.java | 5 +- .../ddl/OracleDropProcedureStatement.java | 29 ++++++++ .../resources/case/ddl/alter-procedure.xml | 1 + .../resources/case/ddl/drop-procedure.xml | 1 + .../sql/supported/ddl/alter-procedure.xml | 1 + .../sql/supported/ddl/drop-procedure.xml | 1 + 10 files changed, 124 insertions(+), 27 deletions(-) create mode 100644 shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleAlterProcedureStatement.java create mode 100644 shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleDropProcedureStatement.java diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/StoreProcedure.g4 b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/StoreProcedure.g4 index 23b2713aae3dd..ed178e0161513 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/StoreProcedure.g4 +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/StoreProcedure.g4 @@ -23,12 +23,28 @@ call : CALL ; +alterProcedure + : ALTER PROCEDURE (schemaName DOT_)? procedureName (procedureCompileClause | (EDITIONABLE | NONEDITIONABLE)) + ; + +procedureCompileClause + : COMPILE DEBUG? (compilerParametersClause)* (REUSE SETTINGS)? + ; + +compilerParametersClause + : parameterName EQ_ parameterName + ; + +dropProcedure + : DROP PROCEDURE (schemaName DOT_)? procedureName + ; + createProcedure : CREATE (OR REPLACE)? (EDITIONABLE | NONEDITIONABLE)? PROCEDURE plsqlProcedureSource ; plsqlProcedureSource - : (schemaName DOT_)? procedureName ( LP_ parameterDeclaration ( COMMA_ parameterDeclaration )* RP_)? sharingClause? + : (schemaName DOT_)? procedureName (LP_ parameterDeclaration (COMMA_ parameterDeclaration)* RP_)? sharingClause? ((defaultCollationClause | invokerRightsClause | accessibleByClause)*)? (IS | AS) (callSpec | declareSection? body) ; @@ -38,8 +54,8 @@ body //need add more statement type according to the doc statement - : ( SIGNED_LEFT_SHIFT_ label SIGNED_RIGHT_SHIFT_ ( SIGNED_LEFT_SHIFT_ label SIGNED_RIGHT_SHIFT_ ) *)? - ( select + : (SIGNED_LEFT_SHIFT_ label SIGNED_RIGHT_SHIFT_ (SIGNED_LEFT_SHIFT_ label SIGNED_RIGHT_SHIFT_) *)? + (select | update | delete | insert @@ -49,7 +65,7 @@ statement ; exceptionHandler - : WHEN ( (typeName (OR typeName)* )| OTHERS ) THEN statement+ + : WHEN ((typeName (OR typeName)*)| OTHERS) THEN statement+ ; declareSection @@ -62,11 +78,11 @@ itemList2 ; cursorDefinition - : CURSOR variableName ( LP_ cursorParameterDec ( COMMA_ cursorParameterDec )* RP_)? ( RETURN rowtype)? IS select SEMI_ + : CURSOR variableName (LP_ cursorParameterDec (COMMA_ cursorParameterDec)* RP_)? (RETURN rowtype)? IS select SEMI_ ; functionDefinition - : functionHeading ( DETERMINISTIC | PIPELINED | PARALLEL_ENABLE | resultCacheClause )+ ( IS | AS ) ( declareSection ? body | callSpec ) + : functionHeading (DETERMINISTIC | PIPELINED | PARALLEL_ENABLE | resultCacheClause)+ (IS | AS) (declareSection ? body | callSpec) ; procedureDefinition @@ -74,15 +90,15 @@ procedureDefinition ; itemList1 - :( typeDefinition | cursorDeclaration | itemDeclaration | functionDeclaration | procedureDeclaration )* + :(typeDefinition | cursorDeclaration | itemDeclaration | functionDeclaration | procedureDeclaration)* ; cursorDeclaration - : CURSOR variableName ( ( cursorParameterDec (COMMA_ cursorParameterDec )* ) )? RETURN rowtype SEMI_ + : CURSOR variableName ((cursorParameterDec (COMMA_ cursorParameterDec)*))? RETURN rowtype SEMI_ ; cursorParameterDec - : variableName IN? dataType ( (COLON_ EQ_ | DEFAULT) expr )? + : variableName IN? dataType ((COLON_ EQ_ | DEFAULT) expr)? ; rowtype @@ -97,8 +113,8 @@ itemDeclaration collectionVariableDecl : variableName ( - typeName ( COLON_ EQ_ ( qualifiedExpression | functionCall | variableName ) )? - | typeName ( COLON_ EQ_ ( collectionConstructor | variableName ) )? + typeName (COLON_ EQ_ (qualifiedExpression | functionCall | variableName))? + | typeName (COLON_ EQ_ (collectionConstructor | variableName))? | typeName MOD_ TYPE ) SEMI_ @@ -133,11 +149,11 @@ typemark ; collectionConstructor - : typeName LP_ ( identifier (COMMA_ identifier)* )? RP_ + : typeName LP_ (identifier (COMMA_ identifier)*)? RP_ ; constantDeclaration - : variableName CONSTANT dataType ( NOT NULL )? ( COLON_ EQ_ | DEFAULT ) expr SEMI_ + : variableName CONSTANT dataType (NOT NULL)? (COLON_ EQ_ | DEFAULT) expr SEMI_ ; cursorVariableDeclaration @@ -149,11 +165,11 @@ exceptionDeclaration ; recordVariableDeclaration - : variableName ( typeName | rowtypeAttribute | typeName MOD_ TYPE ) SEMI_ + : variableName (typeName | rowtypeAttribute | typeName MOD_ TYPE) SEMI_ ; variableDeclaration - : variableName dataType ( ( NOT NULL )? ( COLON_ EQ_ | DEFAULT ) expr )? SEMI_ + : variableName dataType ((NOT NULL)? (COLON_ EQ_ | DEFAULT) expr)? SEMI_ ; typeDefinition @@ -161,22 +177,22 @@ typeDefinition ; recordTypeDefinition - : TYPE typeName IS RECORD LP_ fieldDefinition ( COMMA_ fieldDefinition )* RP_ SEMI_ + : TYPE typeName IS RECORD LP_ fieldDefinition (COMMA_ fieldDefinition)* RP_ SEMI_ ; fieldDefinition - : typeName dataType ( ( NOT NULL )? ( COLON_ EQ_ | DEFAULT ) expr )? + : typeName dataType ((NOT NULL)? (COLON_ EQ_ | DEFAULT) expr)? ; refCursorTypeDefinition - : TYPE typeName IS REF CURSOR ( RETURN ( + : TYPE typeName IS REF CURSOR (RETURN ( (typeName MOD_ ROWTYPE) | (typeName (MOD_ TYPE)?) - ) )? SEMI_ + ))? SEMI_ ; subtypeDefinition - : SUBTYPE typeName IS dataType ( constraint | characterSetClause )? ( NOT NULL )? + : SUBTYPE typeName IS dataType (constraint | characterSetClause)? (NOT NULL)? ; constraint @@ -184,25 +200,25 @@ constraint ; collectionTypeDefinition - : TYPE typeName IS ( assocArrayTypeDef | varrayTypeDef | nestedTableTypeDef ) SEMI_ + : TYPE typeName IS (assocArrayTypeDef | varrayTypeDef | nestedTableTypeDef) SEMI_ ; varrayTypeDef - : ( VARRAY | (VARYING? ARRAY) ) LP_ INTEGER_ RP_ OF dataType ( NOT NULL )? + : (VARRAY | (VARYING? ARRAY)) LP_ INTEGER_ RP_ OF dataType (NOT NULL)? ; nestedTableTypeDef - : TABLE OF dataType ( NOT NULL )? + : TABLE OF dataType (NOT NULL)? ; assocArrayTypeDef - : TABLE OF dataType ( NOT NULL )? INDEX BY ( PLS_INTEGER | BINARY_INTEGER | ( VARCHAR2 | VARCHAR2 | STRING ) LP_ INTEGER_ RP_ | LONG | typeAttribute | rowtypeAttribute ) + : TABLE OF dataType (NOT NULL)? INDEX BY (PLS_INTEGER | BINARY_INTEGER | (VARCHAR2 | VARCHAR2 | STRING) LP_ INTEGER_ RP_ | LONG | typeAttribute | rowtypeAttribute) ; typeAttribute - : ( variableName | objectName ) MOD_ TYPE + : (variableName | objectName) MOD_ TYPE ; rowtypeAttribute - : ( variableName | objectName ) MOD_ ROWTYPE + : (variableName | objectName) MOD_ ROWTYPE ; diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/OracleStatement.g4 b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/OracleStatement.g4 index 9e284a848173b..a1559108ef2f3 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/OracleStatement.g4 +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/OracleStatement.g4 @@ -123,5 +123,7 @@ execute | alterLockdownProfile | alterPluggableDatabase | createProcedure + | dropProcedure + | alterProcedure ) SEMI_? ; diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleDDLStatementSQLVisitor.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleDDLStatementSQLVisitor.java index fa81af7034971..6d56cc56e1a40 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleDDLStatementSQLVisitor.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleDDLStatementSQLVisitor.java @@ -49,6 +49,7 @@ import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AlterPackageContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AlterLockdownProfileContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AlterPluggableDatabaseContext; +import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AlterProcedureContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AlterSequenceContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AlterSessionContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AlterSynonymContext; @@ -101,6 +102,7 @@ import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropOperatorContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropOutlineContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropPackageContext; +import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropProcedureContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropRestorePointContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropRollbackSegmentContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropSynonymContext; @@ -174,6 +176,7 @@ import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAlterOutlineStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAlterPackageStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAlterPluggableDatabaseStatement; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAlterProcedureStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAlterSequenceStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAlterSessionStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAlterSynonymStatement; @@ -219,6 +222,7 @@ import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleDropOperatorStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleDropOutlineStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleDropPackageStatement; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleDropProcedureStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleDropRestorePointStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleDropRollbackSegmentStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleDropSynonymStatement; @@ -984,4 +988,14 @@ public ASTNode visitCreateProcedure(final CreateProcedureContext ctx) { OracleCreateProcedureStatement result = new OracleCreateProcedureStatement(); return result; } + + @Override + public ASTNode visitAlterProcedure(final AlterProcedureContext ctx) { + return new OracleAlterProcedureStatement(); + } + + @Override + public ASTNode visitDropProcedure(final DropProcedureContext ctx) { + return new OracleDropProcedureStatement(); + } } diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleAlterProcedureStatement.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleAlterProcedureStatement.java new file mode 100644 index 0000000000000..663d76118ea37 --- /dev/null +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleAlterProcedureStatement.java @@ -0,0 +1,29 @@ +/* + * 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 lombok.ToString; +import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.AlterProcedureStatement; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.OracleStatement; + +/** + * Oracle alter procedure statement. + */ +@ToString(callSuper = true) +public final class OracleAlterProcedureStatement extends AlterProcedureStatement implements OracleStatement { +} diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleCreateProcedureStatement.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleCreateProcedureStatement.java index af7f53ca7e346..c55b972560c6e 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleCreateProcedureStatement.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleCreateProcedureStatement.java @@ -22,7 +22,10 @@ import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateProcedureStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.OracleStatement; +/** + * Oracle create procedure statement. + */ @Setter @ToString(callSuper = true) -public class OracleCreateProcedureStatement extends CreateProcedureStatement implements OracleStatement { +public final class OracleCreateProcedureStatement extends CreateProcedureStatement implements OracleStatement { } diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleDropProcedureStatement.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleDropProcedureStatement.java new file mode 100644 index 0000000000000..ebd07bd02ac0d --- /dev/null +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleDropProcedureStatement.java @@ -0,0 +1,29 @@ +/* + * 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 lombok.ToString; +import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropProcedureStatement; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.OracleStatement; + +/** + * Oracle drop procedure statement. + */ +@ToString(callSuper = true) +public final class OracleDropProcedureStatement extends DropProcedureStatement implements OracleStatement { +} diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ddl/alter-procedure.xml b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ddl/alter-procedure.xml index 0ac010ebaff60..13c267683beab 100644 --- a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ddl/alter-procedure.xml +++ b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ddl/alter-procedure.xml @@ -23,4 +23,5 @@ + diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ddl/drop-procedure.xml b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ddl/drop-procedure.xml index ef573f50b3a5c..e53db924262a4 100644 --- a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ddl/drop-procedure.xml +++ b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ddl/drop-procedure.xml @@ -19,4 +19,5 @@ + diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ddl/alter-procedure.xml b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ddl/alter-procedure.xml index 5fe25f715ef08..a0d85fbe9b7ee 100644 --- a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ddl/alter-procedure.xml +++ b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ddl/alter-procedure.xml @@ -23,4 +23,5 @@ + diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ddl/drop-procedure.xml b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ddl/drop-procedure.xml index f4974041a1066..f9446a1b36bfc 100644 --- a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ddl/drop-procedure.xml +++ b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ddl/drop-procedure.xml @@ -19,4 +19,5 @@ +