This is an automated email from the ASF dual-hosted git repository.
starocean999 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new bf67d440f3f [Enhancement] (nereids)implement
alterWorkloadPolicyCommand in nereids (#44501)
bf67d440f3f is described below
commit bf67d440f3f34ab35e2095a82944dcece9654f21
Author: Vallish Pai <[email protected]>
AuthorDate: Wed Nov 27 07:08:17 2024 +0530
[Enhancement] (nereids)implement alterWorkloadPolicyCommand in nereids
(#44501)
Issue Number: close #42794
---
.../antlr4/org/apache/doris/nereids/DorisParser.g4 | 4 +-
.../doris/nereids/parser/LogicalPlanBuilder.java | 9 +++
.../apache/doris/nereids/trees/plans/PlanType.java | 1 +
.../plans/commands/AlterWorkloadPolicyCommand.java | 65 ++++++++++++++++++++++
.../trees/plans/visitor/CommandVisitor.java | 5 ++
.../WorkloadSchedPolicyMgr.java | 6 +-
.../test_nereids_workloadpolicy_alter_test.out | 7 +++
.../test_nereids_workloadpolicy_alter_test.groovy | 32 +++++++++++
8 files changed, 125 insertions(+), 4 deletions(-)
diff --git a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
index b1fdda33646..777a0e2d7d7 100644
--- a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
+++ b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
@@ -195,6 +195,8 @@ supportedAlterStatement
| ALTER ROLE role=identifier commentSpec
#alterRole
| ALTER WORKLOAD GROUP name=identifierOrText
properties=propertyClause?
#alterWorkloadGroup
+ | ALTER WORKLOAD POLICY name=identifierOrText
+ properties=propertyClause?
#alterWorkloadPolicy
;
supportedDropStatement
@@ -562,8 +564,6 @@ unsupportedAlterStatement
| ALTER RESOURCE name=identifierOrText properties=propertyClause?
#alterResource
| ALTER COLOCATE GROUP name=multipartIdentifier
SET LEFT_PAREN propertyItemList RIGHT_PAREN
#alterColocateGroup
- | ALTER WORKLOAD POLICY name=identifierOrText
- properties=propertyClause?
#alterWorkloadPolicy
| 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
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
index 216cd60135b..94e499277ca 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
@@ -58,6 +58,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.AlterWorkloadPolicyContext;
import org.apache.doris.nereids.DorisParser.ArithmeticBinaryContext;
import org.apache.doris.nereids.DorisParser.ArithmeticUnaryContext;
import org.apache.doris.nereids.DorisParser.ArrayLiteralContext;
@@ -435,6 +436,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.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;
@@ -4312,6 +4314,13 @@ public class LogicalPlanBuilder extends
DorisParserBaseVisitor<Object> {
return new AlterWorkloadGroupCommand(ctx.name.getText(), properties);
}
+ @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());
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java
index 0b45dde83d2..7fa4db08584 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java
@@ -171,6 +171,7 @@ public enum PlanType {
ALTER_VIEW_COMMAND,
ALTER_STORAGE_VAULT,
ALTER_WORKLOAD_GROUP_COMMAND,
+ ALTER_WORKLOAD_POLICY_COMMAND,
DROP_CATALOG_RECYCLE_BIN_COMMAND,
DROP_ENCRYPTKEY_COMMAND,
UNSET_VARIABLE_COMMAND,
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterWorkloadPolicyCommand.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterWorkloadPolicyCommand.java
new file mode 100644
index 00000000000..42e5250d5b6
--- /dev/null
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterWorkloadPolicyCommand.java
@@ -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);
+ }
+}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java
index 4893ef41be8..a564cb1c140 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java
@@ -23,6 +23,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.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;
@@ -384,6 +385,10 @@ public interface CommandVisitor<R, C> {
return visitCommand(alterWorkloadGroupCommand, context);
}
+ default R visitAlterWorkloadPolicyCommand(AlterWorkloadPolicyCommand
alterWorkloadPolicyCommand, C context) {
+ return visitCommand(alterWorkloadPolicyCommand, context);
+ }
+
default R visitCleanAllProfileCommand(CleanAllProfileCommand
cleanAllProfileCommand, C context) {
return visitCommand(cleanAllProfileCommand, context);
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/resource/workloadschedpolicy/WorkloadSchedPolicyMgr.java
b/fe/fe-core/src/main/java/org/apache/doris/resource/workloadschedpolicy/WorkloadSchedPolicyMgr.java
index 715bdfc5e1e..43f9cd2a794 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/resource/workloadschedpolicy/WorkloadSchedPolicyMgr.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/resource/workloadschedpolicy/WorkloadSchedPolicyMgr.java
@@ -456,15 +456,17 @@ public class WorkloadSchedPolicyMgr extends MasterDaemon
implements Writable, Gs
}
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);
diff --git
a/regression-test/data/workload_manager_p0/test_nereids_workloadpolicy_alter_test.out
b/regression-test/data/workload_manager_p0/test_nereids_workloadpolicy_alter_test.out
new file mode 100644
index 00000000000..ca42544b6bd
--- /dev/null
+++
b/regression-test/data/workload_manager_p0/test_nereids_workloadpolicy_alter_test.out
@@ -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
+
diff --git
a/regression-test/suites/workload_manager_p0/test_nereids_workloadpolicy_alter_test.groovy
b/regression-test/suites/workload_manager_p0/test_nereids_workloadpolicy_alter_test.groovy
new file mode 100644
index 00000000000..e696f09587f
--- /dev/null
+++
b/regression-test/suites/workload_manager_p0/test_nereids_workloadpolicy_alter_test.groovy
@@ -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;"
+
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]