From 39ab5e6b119b3cbb2e87da42e38419acc9fab8e2 Mon Sep 17 00:00:00 2001 From: cambyzhu Date: Thu, 7 Mar 2024 13:23:28 +0800 Subject: [PATCH] support select experimental session variable --- .../java/org/apache/doris/qe/VariableMgr.java | 26 ++++++++++++------- .../nereids_syntax_p0/system_var.groovy | 5 ++++ 2 files changed, 21 insertions(+), 10 deletions(-) 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 93c842f0bfa524..e83fd474dafd73 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 @@ -284,7 +284,10 @@ private static void checkUpdate(SetVar setVar, int flag) throws DdlException { // setVar: variable information that needs to be set public static void setVar(SessionVariable sessionVariable, SetVar setVar) throws DdlException { - VarContext varCtx = setVarPreCheck(setVar); + VarContext varCtx = getVarContext(setVar.getVariable()); + if (varCtx == null) { + ErrorReport.reportDdlException(ErrorCode.ERR_UNKNOWN_SYSTEM_VARIABLE, setVar.getVariable()); + } checkUpdate(setVar, varCtx.getFlag()); setVarInternal(sessionVariable, setVar, varCtx); } @@ -299,7 +302,10 @@ public static void setVar(SessionVariable sessionVariable, SetVar setVar) // So in this case, we should just ignore this exception and return. public static void setVarForNonMasterFE(SessionVariable sessionVariable, SetVar setVar) throws DdlException { - VarContext varCtx = setVarPreCheck(setVar); + VarContext varCtx = getVarContext(setVar.getVariable()); + if (varCtx == null) { + ErrorReport.reportDdlException(ErrorCode.ERR_UNKNOWN_SYSTEM_VARIABLE, setVar.getVariable()); + } try { checkUpdate(setVar, varCtx.getFlag()); } catch (DdlException e) { @@ -311,9 +317,9 @@ public static void setVarForNonMasterFE(SessionVariable sessionVariable, SetVar setVarInternal(sessionVariable, setVar, varCtx); } - @NotNull - private static VarContext setVarPreCheck(SetVar setVar) throws DdlException { - String varName = setVar.getVariable(); + @Nullable + private static VarContext getVarContext(String name) { + String varName = name; boolean hasExpPrefix = false; if (varName.startsWith(VariableAnnotation.EXPERIMENTAL.getPrefix())) { varName = varName.substring(VariableAnnotation.EXPERIMENTAL.getPrefix().length()); @@ -325,13 +331,13 @@ private static VarContext setVarPreCheck(SetVar setVar) throws DdlException { } VarContext ctx = ctxByVarName.get(varName); if (ctx == null) { - ErrorReport.reportDdlException(ErrorCode.ERR_UNKNOWN_SYSTEM_VARIABLE, setVar.getVariable()); + return null; } // for non-matched prefix, report an error VariableAnnotation varType = ctx.getField().getAnnotation(VarAttr.class).varType(); - if (hasExpPrefix && (!setVar.getVariable().startsWith(varType.getPrefix()) + if (hasExpPrefix && (!name.startsWith(varType.getPrefix()) || varType == VariableAnnotation.NONE)) { - ErrorReport.reportDdlException(ErrorCode.ERR_UNKNOWN_SYSTEM_VARIABLE, setVar.getVariable()); + return null; } return ctx; } @@ -533,7 +539,7 @@ public static void replayGlobalVariableV2(GlobalVarPersistInfo info) throws DdlE // Get variable value through variable name, used to satisfy statement like `SELECT @@comment_version` public static void fillValue(SessionVariable var, VariableExpr desc) throws AnalysisException { - VarContext ctx = ctxByVarName.get(desc.getName()); + VarContext ctx = getVarContext(desc.getName()); if (ctx == null) { ErrorReport.reportAnalysisException(ErrorCode.ERR_UNKNOWN_SYSTEM_VARIABLE, desc.getName()); } @@ -621,7 +627,7 @@ public static String getValue(SessionVariable var, VariableExpr desc) throws Ana // For Nereids optimizer public static @Nullable Literal getLiteral(SessionVariable var, String name, SetType setType) { - VarContext ctx = ctxByVarName.get(name); + VarContext ctx = getVarContext(name); if (ctx == null) { return null; } diff --git a/regression-test/suites/nereids_syntax_p0/system_var.groovy b/regression-test/suites/nereids_syntax_p0/system_var.groovy index a2ab3bfa9ed22f..242df6ec94e77e 100644 --- a/regression-test/suites/nereids_syntax_p0/system_var.groovy +++ b/regression-test/suites/nereids_syntax_p0/system_var.groovy @@ -46,4 +46,9 @@ suite("nereids_sys_var") { sql "select @@session.enable_nereids_planner" result ([[true]]) } + + test { + sql "select @@session.experimental_enable_nereids_planner" + result ([[true]]) + } }