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

starocean999 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 95d19858cbd [Enhancement] (nereids)implement DropWorkloadPolicyCommand 
in nereids (#44490)
95d19858cbd is described below

commit 95d19858cbd5f953dfbe06cbb47359a6adfdd769
Author: Vallish Pai <vallish...@gmail.com>
AuthorDate: Wed Nov 27 07:05:23 2024 +0530

    [Enhancement] (nereids)implement DropWorkloadPolicyCommand in nereids 
(#44490)
    
    Issue Number: close #42622
---
 .../antlr4/org/apache/doris/nereids/DorisParser.g4 |  2 +-
 .../doris/nereids/parser/LogicalPlanBuilder.java   |  7 +++
 .../apache/doris/nereids/trees/plans/PlanType.java |  1 +
 .../plans/commands/DropWorkloadPolicyCommand.java  | 61 ++++++++++++++++++++++
 .../trees/plans/visitor/CommandVisitor.java        |  5 ++
 .../WorkloadSchedPolicyMgr.java                    |  7 ++-
 .../test_nereids_workload_policy_test.out          |  6 +++
 .../test_nereids_workload_policy_test.groovy       | 32 ++++++++++++
 8 files changed, 118 insertions(+), 3 deletions(-)

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 932f644fca4..b1fdda33646 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
@@ -204,6 +204,7 @@ supportedDropStatement
     | DROP SQL_BLOCK_RULE (IF EXISTS)? identifierSeq                           
 #dropSqlBlockRule
     | DROP USER (IF EXISTS)? userIdentify                                      
 #dropUser
     | DROP WORKLOAD GROUP (IF EXISTS)? name=identifierOrText                   
 #dropWorkloadGroup
+    | DROP WORKLOAD POLICY (IF EXISTS)? name=identifierOrText                  
 #dropWorkloadPolicy
     ;
 
 supportedShowStatement
@@ -673,7 +674,6 @@ unsupportedDropStatement
         ((FROM | IN) database=identifier)? properties=propertyClause           
 #dropFile
     | DROP INDEX (IF EXISTS)? name=identifier ON tableName=multipartIdentifier 
 #dropIndex
     | DROP RESOURCE (IF EXISTS)? name=identifierOrText                         
 #dropResource
-    | DROP WORKLOAD POLICY (IF EXISTS)? name=identifierOrText                  
 #dropWorkloadPolicy
     | DROP ROW POLICY (IF EXISTS)? policyName=identifier
         ON tableName=multipartIdentifier
         (FOR (userIdentify | ROLE roleName=identifier))?                       
 #dropRowPolicy
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 320043e12b8..216cd60135b 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
@@ -108,6 +108,7 @@ import org.apache.doris.nereids.DorisParser.DropRoleContext;
 import org.apache.doris.nereids.DorisParser.DropSqlBlockRuleContext;
 import org.apache.doris.nereids.DorisParser.DropUserContext;
 import org.apache.doris.nereids.DorisParser.DropWorkloadGroupContext;
+import org.apache.doris.nereids.DorisParser.DropWorkloadPolicyContext;
 import org.apache.doris.nereids.DorisParser.ElementAtContext;
 import org.apache.doris.nereids.DorisParser.ExceptContext;
 import org.apache.doris.nereids.DorisParser.ExceptOrReplaceContext;
@@ -460,6 +461,7 @@ import 
org.apache.doris.nereids.trees.plans.commands.DropRoleCommand;
 import org.apache.doris.nereids.trees.plans.commands.DropSqlBlockRuleCommand;
 import org.apache.doris.nereids.trees.plans.commands.DropUserCommand;
 import org.apache.doris.nereids.trees.plans.commands.DropWorkloadGroupCommand;
+import org.apache.doris.nereids.trees.plans.commands.DropWorkloadPolicyCommand;
 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;
@@ -4400,6 +4402,11 @@ public class LogicalPlanBuilder extends 
DorisParserBaseVisitor<Object> {
         return new DropWorkloadGroupCommand(ctx.name.getText(), ctx.EXISTS() 
!= null);
     }
 
+    @Override
+    public LogicalPlan visitDropWorkloadPolicy(DropWorkloadPolicyContext ctx) {
+        return new DropWorkloadPolicyCommand(ctx.name.getText(), ctx.EXISTS() 
!= null);
+    }
+
     @Override
     public LogicalPlan visitShowTableId(ShowTableIdContext ctx) {
         long tableId = -1;
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 1f7b838edfd..0b45dde83d2 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
@@ -187,6 +187,7 @@ public enum PlanType {
     DROP_SQL_BLOCK_RULE_COMMAND,
     DROP_USER_COMMAND,
     DROP_WORKLOAD_GROUP_NAME,
+    DROP_WORKLOAD_POLICY_COMMAND,
     SHOW_BACKENDS_COMMAND,
     SHOW_BLOCK_RULE_COMMAND,
     SHOW_BROKER_COMMAND,
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DropWorkloadPolicyCommand.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DropWorkloadPolicyCommand.java
new file mode 100644
index 00000000000..96a3c0c69cf
--- /dev/null
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DropWorkloadPolicyCommand.java
@@ -0,0 +1,61 @@
+// 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.catalog.Env;
+import org.apache.doris.common.ErrorCode;
+import org.apache.doris.common.ErrorReport;
+import org.apache.doris.common.FeNameFormat;
+import org.apache.doris.mysql.privilege.PrivPredicate;
+import org.apache.doris.nereids.trees.plans.PlanType;
+import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.qe.StmtExecutor;
+
+/**
+ * drop workload policy command
+ */
+public class DropWorkloadPolicyCommand extends DropCommand {
+    private final boolean ifExists;
+    private final String workloadPolicy;
+
+    /**
+     * constructor
+     */
+    public DropWorkloadPolicyCommand(String workloadPolicy, boolean ifExists) {
+        super(PlanType.DROP_WORKLOAD_POLICY_COMMAND);
+        this.workloadPolicy = workloadPolicy;
+        this.ifExists = ifExists;
+    }
+
+    @Override
+    public void doRun(ConnectContext ctx, StmtExecutor executor) throws 
Exception {
+        // check auth
+        if 
(!Env.getCurrentEnv().getAccessManager().checkGlobalPriv(ConnectContext.get(), 
PrivPredicate.ADMIN)) {
+            
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, 
"ADMIN");
+        }
+
+        FeNameFormat.checkWorkloadSchedPolicyName(workloadPolicy);
+        
Env.getCurrentEnv().getWorkloadSchedPolicyMgr().dropWorkloadSchedPolicy(workloadPolicy,
 ifExists);
+    }
+
+    @Override
+    public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
+        return visitor.visitDropWorkloadPolicyCommand(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 6b801524fb2..4893ef41be8 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
@@ -47,6 +47,7 @@ import 
org.apache.doris.nereids.trees.plans.commands.DropRoleCommand;
 import org.apache.doris.nereids.trees.plans.commands.DropSqlBlockRuleCommand;
 import org.apache.doris.nereids.trees.plans.commands.DropUserCommand;
 import org.apache.doris.nereids.trees.plans.commands.DropWorkloadGroupCommand;
+import org.apache.doris.nereids.trees.plans.commands.DropWorkloadPolicyCommand;
 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.LoadCommand;
@@ -439,6 +440,10 @@ public interface CommandVisitor<R, C> {
         return visitCommand(dropWorkloadGroupCommand, context);
     }
 
+    default R visitDropWorkloadPolicyCommand(DropWorkloadPolicyCommand 
dropWorkloadPolicyCommand, C context) {
+        return visitCommand(dropWorkloadPolicyCommand, context);
+    }
+
     default R visitShowTableIdCommand(ShowTableIdCommand showTableIdCommand, C 
context) {
         return visitCommand(showTableIdCommand, context);
     }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/resource/workloadschedpolicy/WorkloadSchedPolicyMgr.java
 
b/fe/fe-core/src/main/java/org/apache/doris/resource/workloadschedpolicy/WorkloadSchedPolicyMgr.java
index 3879dd83b9a..715bdfc5e1e 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/resource/workloadschedpolicy/WorkloadSchedPolicyMgr.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/resource/workloadschedpolicy/WorkloadSchedPolicyMgr.java
@@ -476,12 +476,15 @@ public class WorkloadSchedPolicyMgr extends MasterDaemon 
implements Writable, Gs
     }
 
     public void dropWorkloadSchedPolicy(DropWorkloadSchedPolicyStmt dropStmt) 
throws UserException {
+        dropWorkloadSchedPolicy(dropStmt.getPolicyName(), 
dropStmt.isIfExists());
+    }
+
+    public void dropWorkloadSchedPolicy(String policyName, boolean isExists) 
throws UserException {
         writeLock();
         try {
-            String policyName = dropStmt.getPolicyName();
             WorkloadSchedPolicy schedPolicy = nameToPolicy.get(policyName);
             if (schedPolicy == null) {
-                if (dropStmt.isIfExists()) {
+                if (isExists) {
                     return;
                 } else {
                     throw new UserException("workload schedule policy " + 
policyName + " not exists");
diff --git 
a/regression-test/data/workload_manager_p0/test_nereids_workload_policy_test.out
 
b/regression-test/data/workload_manager_p0/test_nereids_workload_policy_test.out
new file mode 100644
index 00000000000..8eead574313
--- /dev/null
+++ 
b/regression-test/data/workload_manager_p0/test_nereids_workload_policy_test.out
@@ -0,0 +1,6 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !check_workload_policy_check1 --
+test_nereids_worklod_policy1
+
+-- !check_workload_policy_check2 --
+
diff --git 
a/regression-test/suites/workload_manager_p0/test_nereids_workload_policy_test.groovy
 
b/regression-test/suites/workload_manager_p0/test_nereids_workload_policy_test.groovy
new file mode 100644
index 00000000000..c3b93f9ffa2
--- /dev/null
+++ 
b/regression-test/suites/workload_manager_p0/test_nereids_workload_policy_test.groovy
@@ -0,0 +1,32 @@
+// 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.
+
+suite("test_nereids_workload_policy_test") {
+    sql "drop workload policy if exists test_nereids_worklod_policy1;"
+    sql "create workload policy test_nereids_worklod_policy1 " +
+            "conditions(username='root') " +
+            "actions(set_session_variable 'workload_group=normal') " +
+            "properties( " +
+            "'enabled' = 'false', " +
+            "'priority'='10' " +
+            ");"
+    qt_check_workload_policy_check1("select NAME from 
information_schema.workload_policy where NAME='test_nereids_worklod_policy1';")
+    checkNereidsExecute("drop workload policy  test_nereids_worklod_policy1;")
+    checkNereidsExecute("drop workload policy if exists 
test_nereids_worklod_policy1;")
+    qt_check_workload_policy_check2("select NAME from 
information_schema.workload_policy where NAME='test_nereids_worklod_policy1';")
+
+}
\ No newline at end of file


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

Reply via email to