Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions fe/fe-core/src/main/java/org/apache/doris/common/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -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("\\", "$", "(", ")", "*", "+", ".", "[", "]", "?", "^", "{", "}", "|");
Expand Down Expand Up @@ -389,7 +389,7 @@ public static long getLongPropertyOrDefault(String valStr, long defaultVal, Pred
}

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;
}
Expand Down Expand Up @@ -498,8 +498,8 @@ public static InputStream getInputStreamFromUrl(String urlStr, String encodedAut

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) {
Expand Down Expand Up @@ -700,7 +700,12 @@ public static long sha256long(String str) {
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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public void getRootCauseWithSuppressedMessageRootCauseWithMessageWithMultiSuppre
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));
}

Expand Down Expand Up @@ -90,4 +90,16 @@ public void sha256longEcoding() {
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");
}
}
Loading