[improve](session) print more error msg when set a wrong session variable name (#35775)
## Proposed changes
when set a wrong session variable, eg:
mysql [(none)]>set enable_profileXXXXXXX=true;
ERROR 1228 (HY000): errCode = 2, detailMessage = Unknown system variable
'enable_profileXXXXXXX', the similar variables are {'enable_profile',
'enable_force_spill', 'enable_projection'}
<!--Describe your changes.-->
This commit is contained in:
@ -61,7 +61,8 @@ public enum ErrorCode {
|
||||
ERR_NOT_ALLOWED_COMMAND(1148, new byte[]{'4', '2', '0', '0', '0'}, "The used command is not allowed"
|
||||
+ " with this MySQL version"),
|
||||
ERR_WRONG_COLUMN_NAME(1166, new byte[]{'4', '2', '0', '0', '0'}, "Incorrect column name '%s'. Column regex is '%s'"),
|
||||
ERR_UNKNOWN_SYSTEM_VARIABLE(1193, new byte[]{'H', 'Y', '0', '0', '0'}, "Unknown system variable '%s'"),
|
||||
ERR_UNKNOWN_SYSTEM_VARIABLE(1193, new byte[]{'H', 'Y', '0', '0', '0'}, "Unknown system variable '%s',"
|
||||
+ "the similar variables are %s"),
|
||||
ERR_BAD_SLAVE(1200, new byte[]{'H', 'Y', '0', '0', '0'}, "The server is not configured as slave; fix in config "
|
||||
+ "file or with CHANGE MASTER TO"),
|
||||
ERR_MASTER_INF(1201, new byte[]{'H', 'Y', '0', '0', '0'}, "Could not initialize master info structure; more error"
|
||||
|
||||
@ -41,6 +41,8 @@ import com.google.common.collect.ImmutableSortedMap;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.text.similarity.JaroWinklerDistance;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -59,6 +61,7 @@ import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
@ -287,12 +290,23 @@ public class VariableMgr {
|
||||
throws DdlException {
|
||||
VarContext varCtx = getVarContext(setVar.getVariable());
|
||||
if (varCtx == null) {
|
||||
ErrorReport.reportDdlException(ErrorCode.ERR_UNKNOWN_SYSTEM_VARIABLE, setVar.getVariable());
|
||||
ErrorReport.reportDdlException(ErrorCode.ERR_UNKNOWN_SYSTEM_VARIABLE, setVar.getVariable(),
|
||||
findSimilarSessionVarNames(setVar.getVariable()));
|
||||
}
|
||||
checkUpdate(setVar, varCtx.getFlag());
|
||||
setVarInternal(sessionVariable, setVar, varCtx);
|
||||
}
|
||||
|
||||
public static String findSimilarSessionVarNames(String inputName) {
|
||||
JaroWinklerDistance jaroWinklerDistance = new JaroWinklerDistance();
|
||||
StringJoiner joiner = new StringJoiner(", ", "{", "}");
|
||||
ctxByDisplayVarName.keySet().stream()
|
||||
.sorted(Comparator.comparingDouble(
|
||||
s -> jaroWinklerDistance.apply(StringUtils.upperCase(s), StringUtils.upperCase(inputName))))
|
||||
.limit(3).map(e -> "'" + e + "'").forEach(joiner::add);
|
||||
return joiner.toString();
|
||||
}
|
||||
|
||||
// The only difference between setVar and setVarForNonMasterFE
|
||||
// is that setVarForNonMasterFE will just return if "checkUpdate" throw exception.
|
||||
// This is because, when setting global variables from Non Master FE, Doris will do following step:
|
||||
|
||||
Reference in New Issue
Block a user