Skip to content

Commit 15ee3e3

Browse files
authored
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
1 parent 66242c5 commit 15ee3e3

File tree

10 files changed

+124
-27
lines changed

10 files changed

+124
-27
lines changed

shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/StoreProcedure.g4

+42-26
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,28 @@ call
2323
: CALL
2424
;
2525

26+
alterProcedure
27+
: ALTER PROCEDURE (schemaName DOT_)? procedureName (procedureCompileClause | (EDITIONABLE | NONEDITIONABLE))
28+
;
29+
30+
procedureCompileClause
31+
: COMPILE DEBUG? (compilerParametersClause)* (REUSE SETTINGS)?
32+
;
33+
34+
compilerParametersClause
35+
: parameterName EQ_ parameterName
36+
;
37+
38+
dropProcedure
39+
: DROP PROCEDURE (schemaName DOT_)? procedureName
40+
;
41+
2642
createProcedure
2743
: CREATE (OR REPLACE)? (EDITIONABLE | NONEDITIONABLE)? PROCEDURE plsqlProcedureSource
2844
;
2945

3046
plsqlProcedureSource
31-
: (schemaName DOT_)? procedureName ( LP_ parameterDeclaration ( COMMA_ parameterDeclaration )* RP_)? sharingClause?
47+
: (schemaName DOT_)? procedureName (LP_ parameterDeclaration (COMMA_ parameterDeclaration)* RP_)? sharingClause?
3248
((defaultCollationClause | invokerRightsClause | accessibleByClause)*)? (IS | AS) (callSpec | declareSection? body)
3349
;
3450

@@ -38,8 +54,8 @@ body
3854

3955
//need add more statement type according to the doc
4056
statement
41-
: ( SIGNED_LEFT_SHIFT_ label SIGNED_RIGHT_SHIFT_ ( SIGNED_LEFT_SHIFT_ label SIGNED_RIGHT_SHIFT_ ) *)?
42-
( select
57+
: (SIGNED_LEFT_SHIFT_ label SIGNED_RIGHT_SHIFT_ (SIGNED_LEFT_SHIFT_ label SIGNED_RIGHT_SHIFT_) *)?
58+
(select
4359
| update
4460
| delete
4561
| insert
@@ -49,7 +65,7 @@ statement
4965
;
5066

5167
exceptionHandler
52-
: WHEN ( (typeName (OR typeName)* )| OTHERS ) THEN statement+
68+
: WHEN ((typeName (OR typeName)*)| OTHERS) THEN statement+
5369
;
5470

5571
declareSection
@@ -62,27 +78,27 @@ itemList2
6278
;
6379

6480
cursorDefinition
65-
: CURSOR variableName ( LP_ cursorParameterDec ( COMMA_ cursorParameterDec )* RP_)? ( RETURN rowtype)? IS select SEMI_
81+
: CURSOR variableName (LP_ cursorParameterDec (COMMA_ cursorParameterDec)* RP_)? (RETURN rowtype)? IS select SEMI_
6682
;
6783

6884
functionDefinition
69-
: functionHeading ( DETERMINISTIC | PIPELINED | PARALLEL_ENABLE | resultCacheClause )+ ( IS | AS ) ( declareSection ? body | callSpec )
85+
: functionHeading (DETERMINISTIC | PIPELINED | PARALLEL_ENABLE | resultCacheClause)+ (IS | AS) (declareSection ? body | callSpec)
7086
;
7187

7288
procedureDefinition
7389
: procedureDeclaration (IS | AS) (callSpec | declareSection? body)
7490
;
7591

7692
itemList1
77-
:( typeDefinition | cursorDeclaration | itemDeclaration | functionDeclaration | procedureDeclaration )*
93+
:(typeDefinition | cursorDeclaration | itemDeclaration | functionDeclaration | procedureDeclaration)*
7894
;
7995

8096
cursorDeclaration
81-
: CURSOR variableName ( ( cursorParameterDec (COMMA_ cursorParameterDec )* ) )? RETURN rowtype SEMI_
97+
: CURSOR variableName ((cursorParameterDec (COMMA_ cursorParameterDec)*))? RETURN rowtype SEMI_
8298
;
8399

84100
cursorParameterDec
85-
: variableName IN? dataType ( (COLON_ EQ_ | DEFAULT) expr )?
101+
: variableName IN? dataType ((COLON_ EQ_ | DEFAULT) expr)?
86102
;
87103

88104
rowtype
@@ -97,8 +113,8 @@ itemDeclaration
97113
collectionVariableDecl
98114
: variableName
99115
(
100-
typeName ( COLON_ EQ_ ( qualifiedExpression | functionCall | variableName ) )?
101-
| typeName ( COLON_ EQ_ ( collectionConstructor | variableName ) )?
116+
typeName (COLON_ EQ_ (qualifiedExpression | functionCall | variableName))?
117+
| typeName (COLON_ EQ_ (collectionConstructor | variableName))?
102118
| typeName MOD_ TYPE
103119
)
104120
SEMI_
@@ -133,11 +149,11 @@ typemark
133149
;
134150

135151
collectionConstructor
136-
: typeName LP_ ( identifier (COMMA_ identifier)* )? RP_
152+
: typeName LP_ (identifier (COMMA_ identifier)*)? RP_
137153
;
138154

139155
constantDeclaration
140-
: variableName CONSTANT dataType ( NOT NULL )? ( COLON_ EQ_ | DEFAULT ) expr SEMI_
156+
: variableName CONSTANT dataType (NOT NULL)? (COLON_ EQ_ | DEFAULT) expr SEMI_
141157
;
142158

143159
cursorVariableDeclaration
@@ -149,60 +165,60 @@ exceptionDeclaration
149165
;
150166

151167
recordVariableDeclaration
152-
: variableName ( typeName | rowtypeAttribute | typeName MOD_ TYPE ) SEMI_
168+
: variableName (typeName | rowtypeAttribute | typeName MOD_ TYPE) SEMI_
153169
;
154170

155171
variableDeclaration
156-
: variableName dataType ( ( NOT NULL )? ( COLON_ EQ_ | DEFAULT ) expr )? SEMI_
172+
: variableName dataType ((NOT NULL)? (COLON_ EQ_ | DEFAULT) expr)? SEMI_
157173
;
158174

159175
typeDefinition
160176
: collectionTypeDefinition | recordTypeDefinition | refCursorTypeDefinition | subtypeDefinition
161177
;
162178

163179
recordTypeDefinition
164-
: TYPE typeName IS RECORD LP_ fieldDefinition ( COMMA_ fieldDefinition )* RP_ SEMI_
180+
: TYPE typeName IS RECORD LP_ fieldDefinition (COMMA_ fieldDefinition)* RP_ SEMI_
165181
;
166182

167183
fieldDefinition
168-
: typeName dataType ( ( NOT NULL )? ( COLON_ EQ_ | DEFAULT ) expr )?
184+
: typeName dataType ((NOT NULL)? (COLON_ EQ_ | DEFAULT) expr)?
169185
;
170186

171187
refCursorTypeDefinition
172-
: TYPE typeName IS REF CURSOR ( RETURN (
188+
: TYPE typeName IS REF CURSOR (RETURN (
173189
(typeName MOD_ ROWTYPE)
174190
| (typeName (MOD_ TYPE)?)
175-
) )? SEMI_
191+
))? SEMI_
176192
;
177193

178194
subtypeDefinition
179-
: SUBTYPE typeName IS dataType ( constraint | characterSetClause )? ( NOT NULL )?
195+
: SUBTYPE typeName IS dataType (constraint | characterSetClause)? (NOT NULL)?
180196
;
181197

182198
constraint
183199
: (INTEGER_ COMMA_ INTEGER_) | (RANGE NUMBER_ DOT_ DOT_ NUMBER_)
184200
;
185201

186202
collectionTypeDefinition
187-
: TYPE typeName IS ( assocArrayTypeDef | varrayTypeDef | nestedTableTypeDef ) SEMI_
203+
: TYPE typeName IS (assocArrayTypeDef | varrayTypeDef | nestedTableTypeDef) SEMI_
188204
;
189205

190206
varrayTypeDef
191-
: ( VARRAY | (VARYING? ARRAY) ) LP_ INTEGER_ RP_ OF dataType ( NOT NULL )?
207+
: (VARRAY | (VARYING? ARRAY)) LP_ INTEGER_ RP_ OF dataType (NOT NULL)?
192208
;
193209

194210
nestedTableTypeDef
195-
: TABLE OF dataType ( NOT NULL )?
211+
: TABLE OF dataType (NOT NULL)?
196212
;
197213

198214
assocArrayTypeDef
199-
: TABLE OF dataType ( NOT NULL )? INDEX BY ( PLS_INTEGER | BINARY_INTEGER | ( VARCHAR2 | VARCHAR2 | STRING ) LP_ INTEGER_ RP_ | LONG | typeAttribute | rowtypeAttribute )
215+
: TABLE OF dataType (NOT NULL)? INDEX BY (PLS_INTEGER | BINARY_INTEGER | (VARCHAR2 | VARCHAR2 | STRING) LP_ INTEGER_ RP_ | LONG | typeAttribute | rowtypeAttribute)
200216
;
201217

202218
typeAttribute
203-
: ( variableName | objectName ) MOD_ TYPE
219+
: (variableName | objectName) MOD_ TYPE
204220
;
205221

206222
rowtypeAttribute
207-
: ( variableName | objectName ) MOD_ ROWTYPE
223+
: (variableName | objectName) MOD_ ROWTYPE
208224
;

shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/OracleStatement.g4

+2
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,7 @@ execute
123123
| alterLockdownProfile
124124
| alterPluggableDatabase
125125
| createProcedure
126+
| dropProcedure
127+
| alterProcedure
126128
) SEMI_?
127129
;

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

+14
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AlterPackageContext;
5050
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AlterLockdownProfileContext;
5151
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AlterPluggableDatabaseContext;
52+
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AlterProcedureContext;
5253
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AlterSequenceContext;
5354
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AlterSessionContext;
5455
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AlterSynonymContext;
@@ -101,6 +102,7 @@
101102
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropOperatorContext;
102103
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropOutlineContext;
103104
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropPackageContext;
105+
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropProcedureContext;
104106
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropRestorePointContext;
105107
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropRollbackSegmentContext;
106108
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropSynonymContext;
@@ -174,6 +176,7 @@
174176
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAlterOutlineStatement;
175177
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAlterPackageStatement;
176178
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAlterPluggableDatabaseStatement;
179+
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAlterProcedureStatement;
177180
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAlterSequenceStatement;
178181
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAlterSessionStatement;
179182
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAlterSynonymStatement;
@@ -219,6 +222,7 @@
219222
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleDropOperatorStatement;
220223
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleDropOutlineStatement;
221224
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleDropPackageStatement;
225+
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleDropProcedureStatement;
222226
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleDropRestorePointStatement;
223227
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleDropRollbackSegmentStatement;
224228
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleDropSynonymStatement;
@@ -984,4 +988,14 @@ public ASTNode visitCreateProcedure(final CreateProcedureContext ctx) {
984988
OracleCreateProcedureStatement result = new OracleCreateProcedureStatement();
985989
return result;
986990
}
991+
992+
@Override
993+
public ASTNode visitAlterProcedure(final AlterProcedureContext ctx) {
994+
return new OracleAlterProcedureStatement();
995+
}
996+
997+
@Override
998+
public ASTNode visitDropProcedure(final DropProcedureContext ctx) {
999+
return new OracleDropProcedureStatement();
1000+
}
9871001
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl;
19+
20+
import lombok.ToString;
21+
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.AlterProcedureStatement;
22+
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.OracleStatement;
23+
24+
/**
25+
* Oracle alter procedure statement.
26+
*/
27+
@ToString(callSuper = true)
28+
public final class OracleAlterProcedureStatement extends AlterProcedureStatement implements OracleStatement {
29+
}

shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleCreateProcedureStatement.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateProcedureStatement;
2323
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.OracleStatement;
2424

25+
/**
26+
* Oracle create procedure statement.
27+
*/
2528
@Setter
2629
@ToString(callSuper = true)
27-
public class OracleCreateProcedureStatement extends CreateProcedureStatement implements OracleStatement {
30+
public final class OracleCreateProcedureStatement extends CreateProcedureStatement implements OracleStatement {
2831
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl;
19+
20+
import lombok.ToString;
21+
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropProcedureStatement;
22+
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.OracleStatement;
23+
24+
/**
25+
* Oracle drop procedure statement.
26+
*/
27+
@ToString(callSuper = true)
28+
public final class OracleDropProcedureStatement extends DropProcedureStatement implements OracleStatement {
29+
}

shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ddl/alter-procedure.xml

+1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@
2323
<alter-procedure sql-case-id="alter_procedure_depends_on" />
2424
<alter-procedure sql-case-id="alter_procedure_set_param" />
2525
<alter-procedure sql-case-id="alter_procedure_reset_param" />
26+
<alter-procedure sql-case-id="alter_procedure_for_oracle" />
2627
</sql-parser-test-cases>

shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ddl/drop-procedure.xml

+1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@
1919
<sql-parser-test-cases>
2020
<drop-procedure sql-case-id="drop_procedure" />
2121
<drop-procedure sql-case-id="drop_multiple_procedure" />
22+
<drop-procedure sql-case-id="drop_procedure_for_oracle" />
2223
</sql-parser-test-cases>

shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ddl/alter-procedure.xml

+1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@
2323
<sql-case id="alter_procedure_depends_on" value="ALTER PROCEDURE insert_data(integer, integer) DEPENDS ON EXTENSION myext" db-types="PostgreSQL,openGauss" />
2424
<sql-case id="alter_procedure_set_param" value="ALTER PROCEDURE check_password(text) SET search_path = admin,pg_temp" db-types="PostgreSQL,openGauss" />
2525
<sql-case id="alter_procedure_reset_param" value="ALTER PROCEDURE check_password(text) RESET search_path" db-types="PostgreSQL,openGauss" />
26+
<sql-case id="alter_procedure_for_oracle" value="ALTER PROCEDURE hr.remove_emp COMPILE" db-types="Oracle" />
2627
</sql-cases>

shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ddl/drop-procedure.xml

+1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@
1919
<sql-cases>
2020
<sql-case id="drop_procedure" value="DROP PROCEDURE do_db_maintenance()" db-types="PostgreSQL,openGauss" />
2121
<sql-case id="drop_multiple_procedure" value="DROP PROCEDURE dbo.uspGetSalesbyMonth, dbo.uspUpdateSalesQuotes, dbo.uspGetSalesByYear;" db-types="SQLServer" />
22+
<sql-case id="drop_procedure_for_oracle" value="DROP PROCEDURE hr.remove_emp" db-types="Oracle" />
2223
</sql-cases>

0 commit comments

Comments
 (0)