Skip to content

Commit

Permalink
add alter and drop procedure statement for oracle (#20463)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
tianhao960 authored Aug 24, 2022
1 parent 66242c5 commit 15ee3e3
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
;

Expand All @@ -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
Expand All @@ -49,7 +65,7 @@ statement
;

exceptionHandler
: WHEN ( (typeName (OR typeName)* )| OTHERS ) THEN statement+
: WHEN ((typeName (OR typeName)*)| OTHERS) THEN statement+
;

declareSection
Expand All @@ -62,27 +78,27 @@ 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
: procedureDeclaration (IS | AS) (callSpec | declareSection? body)
;

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
Expand All @@ -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_
Expand Down Expand Up @@ -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
Expand All @@ -149,60 +165,60 @@ 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
: collectionTypeDefinition | recordTypeDefinition | refCursorTypeDefinition | subtypeDefinition
;

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
: (INTEGER_ COMMA_ INTEGER_) | (RANGE NUMBER_ DOT_ DOT_ NUMBER_)
;

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
;
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,7 @@ execute
| alterLockdownProfile
| alterPluggableDatabase
| createProcedure
| dropProcedure
| alterProcedure
) SEMI_?
;
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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 {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
}
Original file line number Diff line number Diff line change
@@ -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 {
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@
<alter-procedure sql-case-id="alter_procedure_depends_on" />
<alter-procedure sql-case-id="alter_procedure_set_param" />
<alter-procedure sql-case-id="alter_procedure_reset_param" />
<alter-procedure sql-case-id="alter_procedure_for_oracle" />
</sql-parser-test-cases>
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@
<sql-parser-test-cases>
<drop-procedure sql-case-id="drop_procedure" />
<drop-procedure sql-case-id="drop_multiple_procedure" />
<drop-procedure sql-case-id="drop_procedure_for_oracle" />
</sql-parser-test-cases>
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@
<sql-case id="alter_procedure_depends_on" value="ALTER PROCEDURE insert_data(integer, integer) DEPENDS ON EXTENSION myext" db-types="PostgreSQL,openGauss" />
<sql-case id="alter_procedure_set_param" value="ALTER PROCEDURE check_password(text) SET search_path = admin,pg_temp" db-types="PostgreSQL,openGauss" />
<sql-case id="alter_procedure_reset_param" value="ALTER PROCEDURE check_password(text) RESET search_path" db-types="PostgreSQL,openGauss" />
<sql-case id="alter_procedure_for_oracle" value="ALTER PROCEDURE hr.remove_emp COMPILE" db-types="Oracle" />
</sql-cases>
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@
<sql-cases>
<sql-case id="drop_procedure" value="DROP PROCEDURE do_db_maintenance()" db-types="PostgreSQL,openGauss" />
<sql-case id="drop_multiple_procedure" value="DROP PROCEDURE dbo.uspGetSalesbyMonth, dbo.uspUpdateSalesQuotes, dbo.uspGetSalesByYear;" db-types="SQLServer" />
<sql-case id="drop_procedure_for_oracle" value="DROP PROCEDURE hr.remove_emp" db-types="Oracle" />
</sql-cases>

0 comments on commit 15ee3e3

Please sign in to comment.