Skip to content

Commit

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

Issue Number: close #42621
  • Loading branch information
Vallishp authored Nov 26, 2024
1 parent 8b9809e commit 78717e3
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,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 GROUP (IF EXISTS)? name=identifierOrText #dropWorkloadGroup
;

supportedShowStatement
Expand Down Expand Up @@ -671,7 +672,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 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
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.DropWorkloadGroupContext;
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 @@ -453,6 +454,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.ExplainCommand;
import org.apache.doris.nereids.trees.plans.commands.ExplainCommand.ExplainLevel;
import org.apache.doris.nereids.trees.plans.commands.ExportCommand;
Expand Down Expand Up @@ -4374,6 +4376,11 @@ public LogicalPlan visitDropUser(DropUserContext ctx) {
return new DropUserCommand(userIdent, ctx.EXISTS() != null);
}

@Override
public LogicalPlan visitDropWorkloadGroup(DropWorkloadGroupContext ctx) {
return new DropWorkloadGroupCommand(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_GROUP_NAME,
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,58 @@
// 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.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 group command
*/
public class DropWorkloadGroupCommand extends DropCommand {
private final boolean ifExists;
private final String workloadGroupName;

/**
* constructor
*/
public DropWorkloadGroupCommand(String workloadGroupName, boolean ifExists) {
super(PlanType.DROP_WORKLOAD_GROUP_NAME);
this.workloadGroupName = workloadGroupName;
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");
}
Env.getCurrentEnv().getWorkloadGroupMgr().dropWorkloadGroup(workloadGroupName, ifExists);
}

@Override
public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
return visitor.visitDropWorkloadGroupCommand(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.DropWorkloadGroupCommand;
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 @@ -424,6 +425,10 @@ default R visitDropUserCommand(DropUserCommand dropUserCommand, C context) {
return visitCommand(dropUserCommand, context);
}

default R visitDropWorkloadGroupCommand(DropWorkloadGroupCommand dropWorkloadGroupCommand, C context) {
return visitCommand(dropWorkloadGroupCommand, 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 @@ -492,7 +492,10 @@ public void alterWorkloadGroup(AlterWorkloadGroupStmt stmt) throws DdlException
}

public void dropWorkloadGroup(DropWorkloadGroupStmt stmt) throws DdlException {
String workloadGroupName = stmt.getWorkloadGroupName();
dropWorkloadGroup(stmt.getWorkloadGroupName(), stmt.isIfExists());
}

public void dropWorkloadGroup(String workloadGroupName, boolean ifExists) throws DdlException {
if (DEFAULT_GROUP_NAME.equals(workloadGroupName) || INTERNAL_GROUP_NAME.equals(workloadGroupName)) {
throw new DdlException("Dropping workload group " + workloadGroupName + " is not allowed");
}
Expand Down Expand Up @@ -521,7 +524,7 @@ public void dropWorkloadGroup(DropWorkloadGroupStmt stmt) throws DdlException {
writeLock();
try {
if (!nameToWorkloadGroup.containsKey(workloadGroupName)) {
if (stmt.isIfExists()) {
if (ifExists) {
return;
}
throw new DdlException("workload group " + workloadGroupName + " does not exist");
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_check1 --
test_nereids_wg1

-- !check_workload_check2 --

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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_test") {
sql "drop workload group if exists test_nereids_wg1;"
sql "drop workload group if exists test_nereids_wg2;"
sql "create workload group test_nereids_wg1 properties('cpu_share'='1024');"
sql "create workload group test_nereids_wg2 properties('cpu_share'='1024');"
qt_check_workload_check1("select NAME from information_schema.workload_groups where NAME='test_nereids_wg1';")
checkNereidsExecute("drop workload group test_nereids_wg1;")
qt_check_workload_check2("select NAME from information_schema.workload_groups where NAME='test_nereids_wg1';")
checkNereidsExecute("drop workload group if exists test_nereids_wg2;")
}

0 comments on commit 78717e3

Please sign in to comment.