This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push:
new a086111a960 [improve](session) print more error msg when set a wrong
session variable name (#35775)
a086111a960 is described below
commit a086111a96094ac11388f46544503cda64acfe5f
Author: zhangstar333 <[email protected]>
AuthorDate: Mon Jun 3 12:45:05 2024 +0800
[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.-->
---
.../src/main/java/org/apache/doris/common/ErrorCode.java | 3 ++-
.../src/main/java/org/apache/doris/qe/VariableMgr.java | 16 +++++++++++++++-
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/common/ErrorCode.java
b/fe/fe-core/src/main/java/org/apache/doris/common/ErrorCode.java
index cf5e0120ba1..51bece5c800 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/common/ErrorCode.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/common/ErrorCode.java
@@ -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"
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 7ca1ad688c5..38a8b5239d3 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
@@ -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:
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]