This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new b8675bc5d20 [Enhancement] [plsql] support drop store procedure 
(#30966) (#31001)
b8675bc5d20 is described below

commit b8675bc5d20d51807c69986e191bf3062e6c53dc
Author: Vallish Pai <vallish...@gmail.com>
AuthorDate: Wed Feb 21 20:30:30 2024 +0530

    [Enhancement] [plsql] support drop store procedure (#30966) (#31001)
---
 .../antlr4/org/apache/doris/nereids/DorisParser.g4 |  1 +
 .../antlr4/org/apache/doris/nereids/PLParser.g4    |  4 ++
 .../doris/nereids/parser/LogicalPlanBuilder.java   |  9 ++++
 .../apache/doris/nereids/trees/plans/PlanType.java |  3 +-
 .../trees/plans/commands/DropProcedureCommand.java | 62 ++++++++++++++++++++++
 .../trees/plans/visitor/CommandVisitor.java        |  5 ++
 .../src/main/java/org/apache/doris/plsql/Exec.java | 33 ++++++++++++
 .../suites/plsql_p0/test_plsql_loop_cursor.groovy  |  4 ++
 8 files changed, 120 insertions(+), 1 deletion(-)

diff --git a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 
b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
index 0389ac5e090..0def8c10ab3 100644
--- a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
+++ b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
@@ -37,6 +37,7 @@ statement
     : statementBase # statementBaseAlias
     | CALL name=multipartIdentifier LEFT_PAREN (expression (COMMA 
expression)*)? RIGHT_PAREN #callProcedure
     | (ALTER | CREATE (OR REPLACE)? | REPLACE) (PROCEDURE | PROC) 
name=multipartIdentifier LEFT_PAREN .*? RIGHT_PAREN .*? #createProcedure
+    | DROP (PROCEDURE | PROC) (IF EXISTS)? name=multipartIdentifier 
#dropProcedure
     ;
 
 statementBase
diff --git a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/PLParser.g4 
b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/PLParser.g4
index e2975f65d00..e49dd9d26b6 100644
--- a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/PLParser.g4
+++ b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/PLParser.g4
@@ -98,6 +98,7 @@ stmt :
      | create_package_body_stmt
      | create_procedure_stmt
      | declare_stmt
+     | drop_procedure_stmt
      | exec_stmt
      | exit_stmt
      | fetch_stmt
@@ -329,6 +330,9 @@ package_body_item :
 create_procedure_stmt :
       (ALTER | CREATE (OR REPLACE)? | REPLACE) (PROCEDURE | PROC) 
multipartIdentifier create_routine_params? create_routine_options? (AS | IS)? 
declare_block_inplace? label_stmt? procedure_block (ident_pl SEMICOLON)?
     ;
+drop_procedure_stmt:
+      DROP (PROCEDURE | PROC) (IF EXISTS)? name=multipartIdentifier
+    ;
 
 create_routine_params :
        LEFT_PAREN RIGHT_PAREN
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
index d408e446b1f..2a6a602b71d 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
@@ -83,6 +83,7 @@ import org.apache.doris.nereids.DorisParser.DeleteContext;
 import org.apache.doris.nereids.DorisParser.DereferenceContext;
 import org.apache.doris.nereids.DorisParser.DropConstraintContext;
 import org.apache.doris.nereids.DorisParser.DropMTMVContext;
+import org.apache.doris.nereids.DorisParser.DropProcedureContext;
 import org.apache.doris.nereids.DorisParser.ElementAtContext;
 import org.apache.doris.nereids.DorisParser.ExistContext;
 import org.apache.doris.nereids.DorisParser.ExplainContext;
@@ -348,6 +349,7 @@ import 
org.apache.doris.nereids.trees.plans.commands.DeleteFromCommand;
 import org.apache.doris.nereids.trees.plans.commands.DeleteFromUsingCommand;
 import org.apache.doris.nereids.trees.plans.commands.DropConstraintCommand;
 import org.apache.doris.nereids.trees.plans.commands.DropMTMVCommand;
+import org.apache.doris.nereids.trees.plans.commands.DropProcedureCommand;
 import org.apache.doris.nereids.trees.plans.commands.ExplainCommand;
 import 
org.apache.doris.nereids.trees.plans.commands.ExplainCommand.ExplainLevel;
 import org.apache.doris.nereids.trees.plans.commands.ExportCommand;
@@ -3286,4 +3288,11 @@ public class LogicalPlanBuilder extends 
DorisParserBaseVisitor<Object> {
             return createProcedurePlan;
         });
     }
+
+    @Override
+    public LogicalPlan visitDropProcedure(DropProcedureContext ctx) {
+        List<String> nameParts = visitMultipartIdentifier(ctx.name);
+        FuncNameInfo procedureName = new FuncNameInfo(nameParts);
+        return ParserUtils.withOrigin(ctx, () -> new 
DropProcedureCommand(procedureName, getOriginSql(ctx)));
+    }
 }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java
index e338bb03ffb..e09d8af389d 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java
@@ -140,5 +140,6 @@ public enum PlanType {
     RESUME_MTMV_COMMAND,
     CANCEL_MTMV_TASK_COMMAND,
     CALL_COMMAND,
-    CREATE_PROCEDURE_COMMAND
+    CREATE_PROCEDURE_COMMAND,
+    DROP_PROCEDURE_COMMAND
 }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DropProcedureCommand.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DropProcedureCommand.java
new file mode 100644
index 00000000000..6aa76197d82
--- /dev/null
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DropProcedureCommand.java
@@ -0,0 +1,62 @@
+// 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.doris.nereids.trees.plans.commands;
+
+import org.apache.doris.nereids.annotation.Developing;
+import org.apache.doris.nereids.trees.plans.PlanType;
+import org.apache.doris.nereids.trees.plans.commands.info.FuncNameInfo;
+import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor;
+import org.apache.doris.plsql.metastore.PlsqlMetaClient;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.qe.StmtExecutor;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.Objects;
+
+/**
+ * Drop table procedure
+ */
+@Developing
+public class DropProcedureCommand extends Command implements ForwardWithSync {
+    public static final Logger LOG = 
LogManager.getLogger(DropProcedureCommand.class);
+    private final FuncNameInfo procedureName;
+    private final String source; // Original SQL, from 
LogicalPlanBuilder.getOriginSql()
+    private final PlsqlMetaClient client;
+
+    /**
+     * constructor
+     */
+    public DropProcedureCommand(FuncNameInfo procedureName, String source) {
+        super(PlanType.DROP_PROCEDURE_COMMAND);
+        this.client = new PlsqlMetaClient();
+        this.procedureName = Objects.requireNonNull(procedureName, 
"procedureName is null");
+        this.source = Objects.requireNonNull(source, "source is null");
+    }
+
+    @Override
+    public void run(ConnectContext ctx, StmtExecutor executor) throws 
Exception {
+        ctx.getPlSqlOperation().getExec().functions.remove(procedureName);
+    }
+
+    @Override
+    public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
+        return visitor.visitDropProcedureCommand(this, context);
+    }
+}
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java
index 107cfd0a1a2..07e9020f1ff 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java
@@ -31,6 +31,7 @@ import 
org.apache.doris.nereids.trees.plans.commands.DeleteFromCommand;
 import org.apache.doris.nereids.trees.plans.commands.DeleteFromUsingCommand;
 import org.apache.doris.nereids.trees.plans.commands.DropConstraintCommand;
 import org.apache.doris.nereids.trees.plans.commands.DropMTMVCommand;
+import org.apache.doris.nereids.trees.plans.commands.DropProcedureCommand;
 import org.apache.doris.nereids.trees.plans.commands.ExplainCommand;
 import org.apache.doris.nereids.trees.plans.commands.ExportCommand;
 import org.apache.doris.nereids.trees.plans.commands.InsertIntoTableCommand;
@@ -141,4 +142,8 @@ public interface CommandVisitor<R, C> {
     default R visitCreateProcedureCommand(CreateProcedureCommand 
createProcedureCommand, C context) {
         return visitCommand(createProcedureCommand, context);
     }
+
+    default R visitDropProcedureCommand(DropProcedureCommand 
dropProcedureCommand, C context) {
+        return visitCommand(dropProcedureCommand, context);
+    }
 }
diff --git a/fe/fe-core/src/main/java/org/apache/doris/plsql/Exec.java 
b/fe/fe-core/src/main/java/org/apache/doris/plsql/Exec.java
index 9a042623da3..98ebebfd4ea 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/plsql/Exec.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/plsql/Exec.java
@@ -47,6 +47,7 @@ import 
org.apache.doris.nereids.PLParser.Declare_cursor_itemContext;
 import org.apache.doris.nereids.PLParser.Declare_handler_itemContext;
 import org.apache.doris.nereids.PLParser.Declare_var_itemContext;
 import org.apache.doris.nereids.PLParser.Doris_statementContext;
+import org.apache.doris.nereids.PLParser.Drop_procedure_stmtContext;
 import org.apache.doris.nereids.PLParser.DtypeContext;
 import org.apache.doris.nereids.PLParser.Dtype_lenContext;
 import org.apache.doris.nereids.PLParser.Exception_block_itemContext;
@@ -1459,6 +1460,38 @@ public class Exec extends 
org.apache.doris.nereids.PLParserBaseVisitor<Integer>
         return null;
     }
 
+    /**
+     * DROP PROCEDURE statement
+     */
+    @Override
+    public Integer visitDrop_procedure_stmt(Drop_procedure_stmtContext ctx) {
+        FuncNameInfo procedureName = new FuncNameInfo(
+                
exec.logicalPlanBuilder.visitMultipartIdentifier(ctx.multipartIdentifier()));
+        if (builtinFunctions.exists(procedureName.toString())) {
+            exec.info(ctx, procedureName.toString() + " is a built-in function 
which cannot be removed.");
+            return 0;
+        }
+        if (trace) {
+            trace(ctx, "DROP PROCEDURE " + procedureName.toString());
+        }
+        exec.functions.remove(procedureName);
+        removeLocalUdf(ctx);
+        return 0;
+    }
+
+    /**
+     * Remove functions and procedures defined in the current script
+     */
+    void removeLocalUdf(ParserRuleContext ctx) {
+        if (exec == this) {
+            String str = Exec.getFormattedText(ctx);
+            int i = localUdf.indexOf(str);
+            if (i != -1) {
+                localUdf.delete(i, i + str.length());
+            }
+        }
+    }
+
     @Override
     public Integer visitSet_doris_session_option(
             Set_doris_session_optionContext ctx) {
diff --git a/regression-test/suites/plsql_p0/test_plsql_loop_cursor.groovy 
b/regression-test/suites/plsql_p0/test_plsql_loop_cursor.groovy
index 0faa8228fa7..72297888aaa 100644
--- a/regression-test/suites/plsql_p0/test_plsql_loop_cursor.groovy
+++ b/regression-test/suites/plsql_p0/test_plsql_loop_cursor.groovy
@@ -59,4 +59,8 @@ suite("test_plsql_loop_cursor") {
     // TODO support print
     sql """call procedure_cursor_select(111, "plsql111")"""
     sql """call procedure_cursor_select(111, "plsql333")"""
+    // TODO call show command before drop
+    sql """DROP PROCEDURE procedure_cursor_select"""
+    sql """DROP PROC procedure_insert"""
+    // TODO call show command after drop
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to