Skip to content

Commit

Permalink
support select experimental session variable
Browse files Browse the repository at this point in the history
  • Loading branch information
cambyzju committed Mar 7, 2024
1 parent 207aba4 commit 39ab5e6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
26 changes: 16 additions & 10 deletions fe/fe-core/src/main/java/org/apache/doris/qe/VariableMgr.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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) {
Expand All @@ -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());
Expand All @@ -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;
}
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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;
}
Expand Down
5 changes: 5 additions & 0 deletions regression-test/suites/nereids_syntax_p0/system_var.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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]])
}
}

0 comments on commit 39ab5e6

Please sign in to comment.