Skip to content

Commit

Permalink
[Enhancement] (nereids)implement CleanAllProfileCommand in nereids (a…
Browse files Browse the repository at this point in the history
…pache#44318)

Issue Number: close apache#42570
  • Loading branch information
Vallishp authored Nov 21, 2024
1 parent ede62c6 commit f663443
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ statementBase
| materializedViewStatement #materializedViewStatementAlias
| supportedJobStatement #supportedJobStatementAlias
| constraintStatement #constraintStatementAlias
| supportedCleanStatement #supportedCleanStatementAlias
| supportedDropStatement #supportedDropStatementAlias
| supportedSetStatement #supportedSetStatementAlias
| supportedUnsetStatement #supportedUnsetStatementAlias
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
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;
Expand Down Expand Up @@ -425,6 +426,7 @@
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;
Expand Down Expand Up @@ -4276,6 +4278,11 @@ public LogicalPlan visitShowFrontends(ShowFrontendsContext ctx) {
return new ShowFrontendsCommand(detail);
}

@Override
public LogicalPlan visitCleanAllProfile(CleanAllProfileContext ctx) {
return new CleanAllProfileCommand();
}

@Override
public LogicalPlan visitShowWhitelist(ShowWhitelistContext ctx) {
return new ShowWhiteListCommand();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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;
Expand Down Expand Up @@ -361,6 +362,10 @@ default R visitAlterRoleCommand(AlterRoleCommand alterRoleCommand, C context) {
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
"""
Expand Down

0 comments on commit f663443

Please sign in to comment.