diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java b/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java index 4daff23a0c..ebb5741671 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java @@ -682,10 +682,12 @@ public class SessionVariable implements Serializable, Writable { * the parallel exec instance num for one Fragment in one BE * 1 means disable this feature */ - @VariableMgr.VarAttr(name = PARALLEL_FRAGMENT_EXEC_INSTANCE_NUM, needForward = true, fuzzy = true) + @VariableMgr.VarAttr(name = PARALLEL_FRAGMENT_EXEC_INSTANCE_NUM, needForward = true, fuzzy = true, + setter = "setFragmentInstanceNum") public int parallelExecInstanceNum = 1; - @VariableMgr.VarAttr(name = PARALLEL_PIPELINE_TASK_NUM, fuzzy = true, needForward = true) + @VariableMgr.VarAttr(name = PARALLEL_PIPELINE_TASK_NUM, fuzzy = true, needForward = true, + setter = "setPipelineTaskNum") public int parallelPipelineTaskNum = 0; @VariableMgr.VarAttr(name = PROFILE_LEVEL, fuzzy = true) @@ -1860,6 +1862,26 @@ public class SessionVariable implements Serializable, Writable { this.queryTimeoutS = this.maxExecutionTimeMS / 1000; } + public void setPipelineTaskNum(String value) throws Exception { + int val = checkFieldValue(PARALLEL_PIPELINE_TASK_NUM, 0, value); + this.parallelPipelineTaskNum = val; + } + + public void setFragmentInstanceNum(String value) throws Exception { + int val = checkFieldValue(PARALLEL_FRAGMENT_EXEC_INSTANCE_NUM, 1, value); + this.parallelExecInstanceNum = val; + } + + private int checkFieldValue(String variableName, int minValue, String value) throws Exception { + int val = Integer.valueOf(value); + if (val < minValue) { + throw new Exception( + variableName + " value should greater than or equal " + String.valueOf(minValue) + + ", you set value is: " + value); + } + return val; + } + public String getWorkloadGroup() { return workloadGroup; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/VariableMgr.java b/fe/fe-core/src/main/java/org/apache/doris/qe/VariableMgr.java index c1052fe99a..c2874a78b8 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/VariableMgr.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/VariableMgr.java @@ -52,6 +52,7 @@ import java.io.IOException; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; @@ -153,6 +154,7 @@ public class VariableMgr { // Set value to a variable private static boolean setValue(Object obj, Field field, String value) throws DdlException { VarAttr attr = field.getAnnotation(VarAttr.class); + if (VariableVarConverters.hasConverter(attr.name())) { value = VariableVarConverters.encode(attr.name(), value).toString(); } @@ -169,6 +171,8 @@ public class VariableMgr { Preconditions.checkArgument(obj instanceof SessionVariable); try { SessionVariable.class.getDeclaredMethod(attr.setter(), String.class).invoke(obj, value); + } catch (InvocationTargetException e) { + ErrorReport.reportDdlException(((InvocationTargetException) e).getTargetException().getMessage()); } catch (Exception e) { ErrorReport.reportDdlException(ErrorCode.ERR_INVALID_VALUE, attr.name(), value, e.getMessage()); } diff --git a/regression-test/framework/src/main/groovy/org/apache/doris/regression/action/TestAction.groovy b/regression-test/framework/src/main/groovy/org/apache/doris/regression/action/TestAction.groovy index 32333c799e..c6b19bccd2 100644 --- a/regression-test/framework/src/main/groovy/org/apache/doris/regression/action/TestAction.groovy +++ b/regression-test/framework/src/main/groovy/org/apache/doris/regression/action/TestAction.groovy @@ -54,11 +54,9 @@ class TestAction implements SuiteAction { private String exception private Closure check SuiteContext context - private Random rd TestAction(SuiteContext context) { this.context = context - this.rd = new Random() } @Override @@ -193,16 +191,6 @@ class TestAction implements SuiteAction { } void sql(String sql, boolean setRandomParallel = true) { - if (setRandomParallel && (! sql.contains('SET_VAR')) && sql.containsIgnoreCase('select')) { - def num = rd.nextInt(16) - def replace_str = 'select /*+SET_VAR(parallel_fragment_exec_instance_num=' + num.toString() + ')*/' - if(sql.contains('SELECT')) { - sql = sql.replaceFirst('SELECT', replace_str) - } - else if (sql.contains('select')) { - sql = sql.replaceFirst('select', replace_str) - } - } this.sql = sql } diff --git a/regression-test/suites/query_p0/session_variable/test_invalid_session.groovy b/regression-test/suites/query_p0/session_variable/test_invalid_session.groovy new file mode 100644 index 0000000000..1980028479 --- /dev/null +++ b/regression-test/suites/query_p0/session_variable/test_invalid_session.groovy @@ -0,0 +1,30 @@ +// 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_invalid_session") { + try { + sql "set parallel_pipeline_task_num = -1;" + } catch (Exception ex) { + assert("${ex}".contains("parallel_pipeline_task_num value should greater than or equal 0, you set value is: -1")) + } + + try { + sql "set parallel_fragment_exec_instance_num = 0;" + } catch (Exception ex) { + assert("${ex}".contains("parallel_fragment_exec_instance_num value should greater than or equal 1, you set value is: 0")) + } +}