Skip to content

Commit

Permalink
[Enhancement] (nereids)implement alterWorkloadPolicyCommand 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 b9bae44
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 5 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 POLICY name=identifierOrText
properties=propertyClause? #alterWorkloadPolicy
;

supportedDropStatement
Expand Down Expand Up @@ -558,9 +560,7 @@ unsupportedAlterStatement
| 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
properties=propertyClause? #alterWorkloadGroup
| ALTER ROUTINE LOAD FOR name=multipartIdentifier properties=propertyClause?
(FROM type=identifier LEFT_PAREN propertyItemList RIGHT_PAREN)? #alterRoutineLoad
| ALTER SQL_BLOCK_RULE name=identifier properties=propertyClause? #alterSqlBlockRule
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.AlterWorkloadPolicyContext;
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.AlterWorkloadPolicyCommand;
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 visitAlterWorkloadPolicy(AlterWorkloadPolicyContext ctx) {
Map<String, String> properties = ctx.propertyClause() != null
? Maps.newHashMap(visitPropertyClause(ctx.propertyClause())) : Maps.newHashMap();
return new AlterWorkloadPolicyCommand(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_POLICY_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,65 @@
// 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 java.util.Map;

/**
* alter workload policy command
*/
public class AlterWorkloadPolicyCommand extends AlterCommand {
private final String workloadPolicyName;
private final Map<String, String> properties;

/**
* constructor
*/
public AlterWorkloadPolicyCommand(String workloadPolicyName, Map<String, String> properties) {
super(PlanType.ALTER_WORKLOAD_POLICY_COMMAND);
this.workloadPolicyName = workloadPolicyName;
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("properties can't be null when alter workload schedule policy");
}
Env.getCurrentEnv().getWorkloadSchedPolicyMgr().alterWorkloadSchedPolicy(workloadPolicyName, properties);
}

@Override
public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
return visitor.visitAlterWorkloadPolicyCommand(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.AlterWorkloadPolicyCommand;
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 visitAlterWorkloadPolicyCommand(AlterWorkloadPolicyCommand alterWorkloadPolicyCommand, C context) {
return visitCommand(alterWorkloadPolicyCommand, 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 @@ -456,15 +456,17 @@ private void checkProperties(Map<String, String> properties, List<Long> wgIdList
}

public void alterWorkloadSchedPolicy(AlterWorkloadSchedPolicyStmt alterStmt) throws UserException {
alterWorkloadSchedPolicy(alterStmt.getPolicyName(), alterStmt.getProperties());
}

public void alterWorkloadSchedPolicy(String policyName, Map<String, String> properties) throws UserException {
writeLock();
try {
String policyName = alterStmt.getPolicyName();
WorkloadSchedPolicy policy = nameToPolicy.get(policyName);
if (policy == null) {
throw new UserException("can not find workload schedule policy " + policyName);
}

Map<String, String> properties = alterStmt.getProperties();
List<Long> wgIdList = new ArrayList<>();
checkProperties(properties, wgIdList);
policy.updatePropertyIfNotNull(properties, wgIdList);
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_policy_check1 --
test_nereids_alter_worklod_policy1 10

-- !check_workload_policy_check2 --
test_nereids_alter_worklod_policy1 17

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_workloadpolicy_alter_test") {
sql "drop workload policy if exists test_nereids_alter_worklod_policy1;"
sql "create workload policy test_nereids_alter_worklod_policy1 " +
"conditions(username='root') " +
"actions(set_session_variable 'workload_group=normal') " +
"properties( " +
"'enabled' = 'false', " +
"'priority'='10');"

qt_check_workload_policy_check1("select NAME,PRIORITY from information_schema.workload_policy where NAME='test_nereids_alter_worklod_policy1';")
checkNereidsExecute("alter workload policy test_nereids_alter_worklod_policy1 properties('priority'='17');")
qt_check_workload_policy_check2("select NAME,PRIORITY from information_schema.workload_policy where NAME='test_nereids_alter_worklod_policy1';")
sql "drop workload policy if exists test_nereids_alter_worklod_policy1;"

}

0 comments on commit b9bae44

Please sign in to comment.