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 f663443fcbe [Enhancement] (nereids)implement CleanAllProfileCommand in 
nereids (#44318)
f663443fcbe is described below

commit f663443fcbe73aa27aff8ff64a4e065ba505bde5
Author: Vallish Pai <[email protected]>
AuthorDate: Thu Nov 21 13:44:38 2024 +0530

    [Enhancement] (nereids)implement CleanAllProfileCommand in nereids (#44318)
    
    Issue Number: close #42570
---
 .../antlr4/org/apache/doris/nereids/DorisParser.g4 |  6 +-
 .../doris/nereids/parser/LogicalPlanBuilder.java   |  7 +++
 .../apache/doris/nereids/trees/plans/PlanType.java |  1 +
 .../plans/commands/CleanAllProfileCommand.java     | 66 ++++++++++++++++++++++
 .../trees/plans/visitor/CommandVisitor.java        |  5 ++
 .../auth_call/test_dml_cancel_profile_auth.groovy  |  1 +
 6 files changed, 85 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 2ab16278525..177eff9b6db 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
@@ -52,6 +52,7 @@ statementBase
     | materializedViewStatement         #materializedViewStatementAlias
     | supportedJobStatement             #supportedJobStatementAlias
     | constraintStatement               #constraintStatementAlias
+    | supportedCleanStatement           #supportedCleanStatementAlias
     | supportedDropStatement            #supportedDropStatementAlias
     | supportedSetStatement             #supportedSetStatementAlias
     | supportedUnsetStatement           #supportedUnsetStatementAlias
@@ -426,6 +427,10 @@ supportedRefreshStatement
     : REFRESH CATALOG name=identifier propertyClause?                          
     #refreshCatalog
     ;
 
+supportedCleanStatement
+    : CLEAN ALL PROFILE                                                        
     #cleanAllProfile
+    ;
+
 unsupportedRefreshStatement
     : REFRESH TABLE name=multipartIdentifier                                   
     #refreshTable
     | REFRESH DATABASE name=multipartIdentifier propertyClause?                
     #refreshDatabase
@@ -434,7 +439,6 @@ unsupportedRefreshStatement
 
 unsupportedCleanStatement
     : CLEAN LABEL label=identifier? (FROM | IN) database=identifier            
     #cleanLabel
-    | CLEAN ALL PROFILE                                                        
     #cleanAllProfile
     | CLEAN QUERY STATS ((FOR database=identifier)
         | ((FROM | IN) table=multipartIdentifier))                             
     #cleanQueryStats
     | CLEAN ALL QUERY STATS                                                    
     #cleanAllQueryStats
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 fd84a448c7c..d24e4c1fa7b 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
@@ -70,6 +70,7 @@ import org.apache.doris.nereids.DorisParser.BuildModeContext;
 import org.apache.doris.nereids.DorisParser.CallProcedureContext;
 import org.apache.doris.nereids.DorisParser.CancelMTMVTaskContext;
 import org.apache.doris.nereids.DorisParser.CastDataTypeContext;
+import org.apache.doris.nereids.DorisParser.CleanAllProfileContext;
 import org.apache.doris.nereids.DorisParser.CollateContext;
 import org.apache.doris.nereids.DorisParser.ColumnDefContext;
 import org.apache.doris.nereids.DorisParser.ColumnDefsContext;
@@ -425,6 +426,7 @@ import 
org.apache.doris.nereids.trees.plans.commands.AlterViewCommand;
 import org.apache.doris.nereids.trees.plans.commands.CallCommand;
 import org.apache.doris.nereids.trees.plans.commands.CancelJobTaskCommand;
 import org.apache.doris.nereids.trees.plans.commands.CancelMTMVTaskCommand;
+import org.apache.doris.nereids.trees.plans.commands.CleanAllProfileCommand;
 import org.apache.doris.nereids.trees.plans.commands.Command;
 import org.apache.doris.nereids.trees.plans.commands.Constraint;
 import org.apache.doris.nereids.trees.plans.commands.CreateJobCommand;
@@ -4276,6 +4278,11 @@ public class LogicalPlanBuilder extends 
DorisParserBaseVisitor<Object> {
         return new ShowFrontendsCommand(detail);
     }
 
+    @Override
+    public LogicalPlan visitCleanAllProfile(CleanAllProfileContext ctx) {
+        return new CleanAllProfileCommand();
+    }
+
     @Override
     public LogicalPlan visitShowWhitelist(ShowWhitelistContext ctx) {
         return new ShowWhiteListCommand();
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 291bfd3697a..c3d7fc70801 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
@@ -166,6 +166,7 @@ public enum PlanType {
     SHOW_PROCEDURE_COMMAND,
     SHOW_CREATE_PROCEDURE_COMMAND,
     CREATE_VIEW_COMMAND,
+    CLEAN_ALL_PROFILE_COMMAND,
     ALTER_ROLE_COMMAND,
     ALTER_VIEW_COMMAND,
     ALTER_STORAGE_VAULT,
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CleanAllProfileCommand.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CleanAllProfileCommand.java
new file mode 100644
index 00000000000..937148b5989
--- /dev/null
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CleanAllProfileCommand.java
@@ -0,0 +1,66 @@
+// 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.analysis.RedirectStatus;
+import org.apache.doris.analysis.StmtType;
+import org.apache.doris.catalog.Env;
+import org.apache.doris.common.ErrorCode;
+import org.apache.doris.common.ErrorReport;
+import org.apache.doris.common.profile.ProfileManager;
+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;
+
+/**
+ * clean profile command
+ */
+public class CleanAllProfileCommand extends Command implements Redirect {
+
+    /**
+     * constructor
+     */
+    public CleanAllProfileCommand() {
+        super(PlanType.CLEAN_ALL_PROFILE_COMMAND);
+    }
+
+    @Override
+    public void run(ConnectContext ctx, StmtExecutor executor) throws 
Exception {
+        if 
(!Env.getCurrentEnv().getAccessManager().checkGlobalPriv(ConnectContext.get(), 
PrivPredicate.ADMIN)) {
+            
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, 
"ADMIN");
+        }
+        ProfileManager.getInstance().cleanProfile();
+    }
+
+    @Override
+    public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
+        return visitor.visitCleanAllProfileCommand(this, context);
+    }
+
+    @Override
+    public RedirectStatus toRedirectStatus() {
+        return RedirectStatus.NO_FORWARD;
+    }
+
+    @Override
+    public StmtType stmtType() {
+        return StmtType.CLEAN;
+    }
+}
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 50df22f209f..7aa935df8bf 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
@@ -25,6 +25,7 @@ import 
org.apache.doris.nereids.trees.plans.commands.AlterViewCommand;
 import org.apache.doris.nereids.trees.plans.commands.CallCommand;
 import org.apache.doris.nereids.trees.plans.commands.CancelJobTaskCommand;
 import org.apache.doris.nereids.trees.plans.commands.CancelMTMVTaskCommand;
+import org.apache.doris.nereids.trees.plans.commands.CleanAllProfileCommand;
 import org.apache.doris.nereids.trees.plans.commands.Command;
 import org.apache.doris.nereids.trees.plans.commands.CreateJobCommand;
 import org.apache.doris.nereids.trees.plans.commands.CreateMTMVCommand;
@@ -361,6 +362,10 @@ public interface CommandVisitor<R, C> {
         return visitCommand(alterRoleCommand, context);
     }
 
+    default R visitCleanAllProfileCommand(CleanAllProfileCommand 
cleanAllProfileCommand, C context) {
+        return visitCommand(cleanAllProfileCommand, context);
+    }
+
     default R visitShowFrontendsCommand(ShowFrontendsCommand 
showFrontendsCommand, C context) {
         return visitCommand(showFrontendsCommand, context);
     }
diff --git 
a/regression-test/suites/auth_call/test_dml_cancel_profile_auth.groovy 
b/regression-test/suites/auth_call/test_dml_cancel_profile_auth.groovy
index 82656726e65..84c5a5ef5ba 100644
--- a/regression-test/suites/auth_call/test_dml_cancel_profile_auth.groovy
+++ b/regression-test/suites/auth_call/test_dml_cancel_profile_auth.groovy
@@ -45,6 +45,7 @@ 
suite("test_dml_cancel_profile_auth","p0,auth_call,nonConcurrent") {
     }
     sql """grant admin_priv on *.*.* to ${user}"""
     connect(user=user, password="${pwd}", url=context.config.jdbcUrl) {
+        checkNereidsExecute("CLEAN ALL PROFILE")
         sql """
             CLEAN ALL PROFILE;
             """


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to