Skip to content

Commit

Permalink
[Enhancement] (nereids)implement DropWorkloadPolicyCommand in nereids
Browse files Browse the repository at this point in the history
  • Loading branch information
Vallishp committed Nov 22, 2024
1 parent 5b20207 commit b484886
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 @@ -199,6 +199,7 @@ supportedDropStatement
| DROP ROLE (IF EXISTS)? name=identifier #dropRole
| DROP SQL_BLOCK_RULE (IF EXISTS)? identifierSeq #dropSqlBlockRule
| DROP USER (IF EXISTS)? userIdentify #dropUser
| DROP WORKLOAD POLICY (IF EXISTS)? name=identifierOrText #dropWorkloadPolicy
;

supportedShowStatement
Expand Down Expand Up @@ -668,7 +669,6 @@ unsupportedDropStatement
| DROP INDEX (IF EXISTS)? name=identifier ON tableName=multipartIdentifier #dropIndex
| DROP RESOURCE (IF EXISTS)? name=identifierOrText #dropResource
| DROP WORKLOAD GROUP (IF EXISTS)? name=identifierOrText #dropWorkloadGroup
| DROP WORKLOAD POLICY (IF EXISTS)? name=identifierOrText #dropWorkloadPolicy
| DROP ENCRYPTKEY (IF EXISTS)? name=multipartIdentifier #dropEncryptkey
| DROP ROW POLICY (IF EXISTS)? policyName=identifier
ON tableName=multipartIdentifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,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.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 @@ -451,6 +452,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.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 @@ -4359,6 +4361,11 @@ public LogicalPlan visitDropUser(DropUserContext ctx) {
return new DropUserCommand(userIdent, 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 @@ -184,6 +184,7 @@ public enum PlanType {
EXECUTE_COMMAND,
DROP_SQL_BLOCK_RULE_COMMAND,
DROP_USER_COMMAND,
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 @@ -44,6 +44,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.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 @@ -414,6 +415,10 @@ default R visitDropUserCommand(DropUserCommand dropUserCommand, C context) {
return visitCommand(dropUserCommand, 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 group 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 group 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 b484886

Please sign in to comment.