Skip to content

Commit

Permalink
[Enhancement] (nereids)implement alterWorkloadGroupCommand in nereids
Browse files Browse the repository at this point in the history
  • Loading branch information
Vallishp committed Nov 23, 2024
1 parent 362efda commit fb6787c
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ supportedAlterStatement
AS query #alterView
| ALTER STORAGE VAULT name=multipartIdentifier properties=propertyClause #alterStorageVault
| ALTER ROLE role=identifier commentSpec #alterRole
| ALTER WORKLOAD GROUP name=identifierOrText
properties=propertyClause? #alterWorkloadGroup
;

supportedDropStatement
Expand Down Expand Up @@ -557,8 +559,6 @@ unsupportedAlterStatement
| ALTER RESOURCE name=identifierOrText properties=propertyClause? #alterResource
| ALTER COLOCATE GROUP name=multipartIdentifier
SET LEFT_PAREN propertyItemList RIGHT_PAREN #alterColocateGroup
| ALTER WORKLOAD GROUP name=identifierOrText
properties=propertyClause? #alterWorkloadGroup
| ALTER WORKLOAD POLICY name=identifierOrText
properties=propertyClause? #alterWorkloadPolicy
| ALTER ROUTINE LOAD FOR name=multipartIdentifier properties=propertyClause?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.apache.doris.nereids.DorisParser.AlterRoleContext;
import org.apache.doris.nereids.DorisParser.AlterStorageVaultContext;
import org.apache.doris.nereids.DorisParser.AlterViewContext;
import org.apache.doris.nereids.DorisParser.AlterWorkloadGroupContext;
import org.apache.doris.nereids.DorisParser.ArithmeticBinaryContext;
import org.apache.doris.nereids.DorisParser.ArithmeticUnaryContext;
import org.apache.doris.nereids.DorisParser.ArrayLiteralContext;
Expand Down Expand Up @@ -428,6 +429,7 @@
import org.apache.doris.nereids.trees.plans.commands.AlterRoleCommand;
import org.apache.doris.nereids.trees.plans.commands.AlterStorageVaultCommand;
import org.apache.doris.nereids.trees.plans.commands.AlterViewCommand;
import org.apache.doris.nereids.trees.plans.commands.AlterWorkloadGroupCommand;
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;
Expand Down Expand Up @@ -4283,12 +4285,20 @@ public LogicalPlan visitShowCreateMaterializedView(ShowCreateMaterializedViewCon
return new ShowCreateMaterializedViewCommand(stripQuotes(ctx.mvName.getText()), new TableNameInfo(nameParts));
}

@Override
public LogicalPlan visitAlterWorkloadGroup(AlterWorkloadGroupContext ctx) {
Map<String, String> properties = ctx.propertyClause() != null
? Maps.newHashMap(visitPropertyClause(ctx.propertyClause())) : Maps.newHashMap();
return new AlterWorkloadGroupCommand(ctx.name.getText(), properties);
}

@Override
public LogicalPlan visitAlterRole(AlterRoleContext ctx) {
String comment = visitCommentSpec(ctx.commentSpec());
return new AlterRoleCommand(ctx.role.getText(), comment);
}

@Override
public LogicalPlan visitShowFrontends(ShowFrontendsContext ctx) {
String detail = (ctx.name != null) ? ctx.name.getText() : null;
return new ShowFrontendsCommand(detail);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ public enum PlanType {
ALTER_ROLE_COMMAND,
ALTER_VIEW_COMMAND,
ALTER_STORAGE_VAULT,
ALTER_WORKLOAD_GROUP_COMMAND,
DROP_CATALOG_RECYCLE_BIN_COMMAND,
UNSET_VARIABLE_COMMAND,
UNSET_DEFAULT_STORAGE_VAULT_COMMAND,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// 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.AnalysisException;
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;
import org.apache.doris.resource.workloadgroup.WorkloadGroup;
import org.apache.doris.resource.workloadgroup.WorkloadGroupMgr;

import org.apache.commons.lang3.StringUtils;

import java.util.Map;

/**
* alter workload group command
*/
public class AlterWorkloadGroupCommand extends AlterCommand {
private final String workloadGroupName;
private final Map<String, String> properties;

/**
* constructor
*/
public AlterWorkloadGroupCommand(String workloadGroupName, Map<String, String> properties) {
super(PlanType.ALTER_WORKLOAD_GROUP_COMMAND);
this.workloadGroupName = workloadGroupName;
this.properties = properties;
}

@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");
}

if (properties == null || properties.isEmpty()) {
throw new AnalysisException("Workload Group properties can't be empty");
}

if (properties.containsKey(WorkloadGroup.INTERNAL_TYPE)) {
throw new AnalysisException(WorkloadGroup.INTERNAL_TYPE + " can not be create or modified ");
}
String tagStr = properties.get(WorkloadGroup.TAG);
if (!StringUtils.isEmpty(tagStr) && (WorkloadGroupMgr.DEFAULT_GROUP_NAME.equals(workloadGroupName)
|| WorkloadGroupMgr.INTERNAL_GROUP_NAME.equals(workloadGroupName))) {
throw new AnalysisException(
WorkloadGroupMgr.INTERNAL_GROUP_NAME + " and " + WorkloadGroupMgr.DEFAULT_GROUP_NAME
+ " group can not set tag");
}

Env.getCurrentEnv().getWorkloadGroupMgr().alterWorkloadGroup(workloadGroupName, properties);
}

@Override
public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
return visitor.visitAlterWorkloadGroupCommand(this, context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.doris.nereids.trees.plans.commands.AlterMTMVCommand;
import org.apache.doris.nereids.trees.plans.commands.AlterRoleCommand;
import org.apache.doris.nereids.trees.plans.commands.AlterViewCommand;
import org.apache.doris.nereids.trees.plans.commands.AlterWorkloadGroupCommand;
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;
Expand Down Expand Up @@ -371,6 +372,10 @@ default R visitAlterRoleCommand(AlterRoleCommand alterRoleCommand, C context) {
return visitCommand(alterRoleCommand, context);
}

default R visitAlterWorkloadGroupCommand(AlterWorkloadGroupCommand alterWorkloadGroupCommand, C context) {
return visitCommand(alterWorkloadGroupCommand, context);
}

default R visitCleanAllProfileCommand(CleanAllProfileCommand cleanAllProfileCommand, C context) {
return visitCommand(cleanAllProfileCommand, context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,10 @@ private void checkGlobalUnlock(WorkloadGroup newWg, WorkloadGroup oldWg) throws
}

public void alterWorkloadGroup(AlterWorkloadGroupStmt stmt) throws DdlException {
String workloadGroupName = stmt.getWorkloadGroupName();
Map<String, String> properties = stmt.getProperties();
alterWorkloadGroup(stmt.getWorkloadGroupName(), stmt.getProperties());
}

public void alterWorkloadGroup(String workloadGroupName, Map<String, String> properties) throws DdlException {
if (properties.size() == 0) {
throw new DdlException("alter workload group should contain at least one property");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !check_workload_check1 --
1024 10

-- !check_workload_check2 --
20 8

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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_alter_wg1;"
sql "create workload group test_nereids_alter_wg1 properties('cpu_share'='1024', 'scan_thread_num'='10');"
qt_check_workload_check1("select CPU_SHARE,scan_thread_num from information_schema.workload_groups where NAME='test_nereids_alter_wg1';")
checkNereidsExecute("Alter workload group test_nereids_alter_wg1 properties('cpu_share'='20', 'scan_thread_num'='8');")
qt_check_workload_check2("select CPU_SHARE,scan_thread_num from information_schema.workload_groups where NAME='test_nereids_alter_wg1';")
checkNereidsExecute("drop workload group if exists test_nereids_alter_wg1;")
}

0 comments on commit fb6787c

Please sign in to comment.