Skip to content

Commit

Permalink
[Enhancement] (nereids)implement DropWorkloadPolicyCommand in nereids (
Browse files Browse the repository at this point in the history
…#44490)

Issue Number: close #42622
  • Loading branch information
Vallishp authored Nov 27, 2024
1 parent 54f87af commit 95d1985
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
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;
Expand Down Expand Up @@ -460,6 +461,7 @@
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;
Expand Down Expand Up @@ -4400,6 +4402,11 @@ public LogicalPlan visitDropWorkloadGroup(DropWorkloadGroupContext ctx) {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
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;
Expand Down Expand Up @@ -439,6 +440,10 @@ default R visitDropWorkloadGroupCommand(DropWorkloadGroupCommand dropWorkloadGro
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,12 +476,15 @@ public void alterWorkloadSchedPolicy(AlterWorkloadSchedPolicyStmt alterStmt) thr
}

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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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 --

Original file line number Diff line number Diff line change
@@ -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';")

}

0 comments on commit 95d1985

Please sign in to comment.