This is an automated email from the ASF dual-hosted git repository.
dataroaring pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-3.0 by this push:
new 5ae407cbe57 branch-3.0: [bugfix](catalog) replace Math.abs with
bitwise AND to ensure non-negative ID generation #55183 (#55708)
5ae407cbe57 is described below
commit 5ae407cbe5745fb6d6b570243c7eae34175543be
Author: lw112 <[email protected]>
AuthorDate: Thu Sep 11 09:45:09 2025 +0800
branch-3.0: [bugfix](catalog) replace Math.abs with bitwise AND to ensure
non-negative ID generation #55183 (#55708)
### What problem does this PR solve?
pick: #55183
---
.../src/main/java/org/apache/doris/common/util/Util.java | 15 ++++++++++-----
.../test/java/org/apache/doris/common/util/UtilTest.java | 16 ++++++++++++++--
2 files changed, 24 insertions(+), 7 deletions(-)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/common/util/Util.java
b/fe/fe-core/src/main/java/org/apache/doris/common/util/Util.java
index 0612b3794c6..14843578bc9 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/common/util/Util.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/common/util/Util.java
@@ -66,7 +66,7 @@ public class Util {
private static final long DEFAULT_EXEC_CMD_TIMEOUT_MS = 600000L;
private static final String[] ORDINAL_SUFFIX
- = new String[] { "th", "st", "nd", "rd", "th", "th", "th", "th",
"th", "th" };
+ = new String[] {"th", "st", "nd", "rd", "th", "th", "th", "th",
"th", "th"};
private static final List<String> REGEX_ESCAPES
= Lists.newArrayList("\\", "$", "(", ")", "*", "+", ".", "[", "]",
"?", "^", "{", "}", "|");
@@ -389,7 +389,7 @@ public class Util {
}
public static double getDoublePropertyOrDefault(String valStr, double
defaultVal, Predicate<Double> pred,
- String hintMsg) throws
AnalysisException {
+ String hintMsg) throws AnalysisException {
if (Strings.isNullOrEmpty(valStr)) {
return defaultVal;
}
@@ -498,8 +498,8 @@ public class Util {
public static boolean showHiddenColumns() {
return ConnectContext.get() != null && (
- ConnectContext.get().getSessionVariable().showHiddenColumns()
- ||
ConnectContext.get().getSessionVariable().skipStorageEngineMerge());
+ ConnectContext.get().getSessionVariable().showHiddenColumns()
+ ||
ConnectContext.get().getSessionVariable().skipStorageEngineMerge());
}
public static String escapeSingleRegex(String s) {
@@ -700,7 +700,12 @@ public class Util {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] hash = digest.digest(str.getBytes(StandardCharsets.UTF_8));
ByteBuffer buffer = ByteBuffer.wrap(hash);
- return buffer.getLong();
+ long result = buffer.getLong();
+ // Handle Long.MIN_VALUE case to ensure non-negative ID generation
+ if (result == Long.MIN_VALUE) {
+ return str.hashCode();
+ }
+ return result;
} catch (NoSuchAlgorithmException e) {
return str.hashCode();
}
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/common/util/UtilTest.java
b/fe/fe-core/src/test/java/org/apache/doris/common/util/UtilTest.java
index dc8419ddd1f..5a67a0ad5c2 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/common/util/UtilTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/common/util/UtilTest.java
@@ -45,8 +45,8 @@ public class UtilTest {
rootCause.addSuppressed(new Exception("Suppressed message2"));
Assertions.assertEquals(
"java.lang.Exception: Root cause message"
- + " With suppressed[0]:Suppressed message"
- + " With suppressed[1]:Suppressed message2",
+ + " With suppressed[0]:Suppressed message"
+ + " With suppressed[1]:Suppressed message2",
Util.getRootCauseWithSuppressedMessage(rootCause));
}
@@ -90,4 +90,16 @@ public class UtilTest {
String str1 = "东方卫视";
Assertions.assertNotEquals(Util.sha256long(str),
Util.sha256long(str1));
}
+
+ @Test
+ public void sha256longHandlesLongMinValue() {
+ String testStr = "test_long_min_value_case";
+ long result = Util.sha256long(testStr);
+
+ Assertions.assertNotEquals(Long.MIN_VALUE, result,
+ "sha256long should not return Long.MIN_VALUE");
+
+ Assertions.assertEquals(result, Util.sha256long(testStr),
+ "Same input should produce same output");
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]