You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by le...@apache.org on 2022/06/30 01:12:08 UTC
[hudi] branch master updated: [HUDI-4336] Fix records overwritten bug with binary primary key (#5996)
This is an automated email from the ASF dual-hosted git repository.
leesf pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hudi.git
The following commit(s) were added to refs/heads/master by this push:
new 3948b8935a [HUDI-4336] Fix records overwritten bug with binary primary key (#5996)
3948b8935a is described below
commit 3948b8935a79e0773e1e4d77bb1ded5edd7e8d4f
Author: luoyajun <lu...@gmail.com>
AuthorDate: Thu Jun 30 09:12:00 2022 +0800
[HUDI-4336] Fix records overwritten bug with binary primary key (#5996)
---
.../java/org/apache/hudi/common/util/StringUtils.java | 6 +++++-
.../java/org/apache/hudi/common/util/TestStringUtils.java | 15 +++++++++++++++
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/hudi-common/src/main/java/org/apache/hudi/common/util/StringUtils.java b/hudi-common/src/main/java/org/apache/hudi/common/util/StringUtils.java
index 3e1a1a9cc7..a18c3b20eb 100644
--- a/hudi-common/src/main/java/org/apache/hudi/common/util/StringUtils.java
+++ b/hudi-common/src/main/java/org/apache/hudi/common/util/StringUtils.java
@@ -19,6 +19,7 @@
package org.apache.hudi.common.util;
import javax.annotation.Nullable;
+import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@@ -88,7 +89,10 @@ public class StringUtils {
}
public static String objToString(@Nullable Object obj) {
- return obj == null ? null : obj.toString();
+ if (obj == null) {
+ return null;
+ }
+ return obj instanceof ByteBuffer ? toHexString(((ByteBuffer) obj).array()) : obj.toString();
}
/**
diff --git a/hudi-common/src/test/java/org/apache/hudi/common/util/TestStringUtils.java b/hudi-common/src/test/java/org/apache/hudi/common/util/TestStringUtils.java
index 5f1bcd3c06..a98e22ccbc 100644
--- a/hudi-common/src/test/java/org/apache/hudi/common/util/TestStringUtils.java
+++ b/hudi-common/src/test/java/org/apache/hudi/common/util/TestStringUtils.java
@@ -20,6 +20,7 @@ package org.apache.hudi.common.util;
import org.junit.jupiter.api.Test;
+import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
@@ -51,6 +52,20 @@ public class TestStringUtils {
assertEquals("", StringUtils.nullToEmpty(null));
}
+ @Test
+ public void testStringObjToString() {
+ assertNull(StringUtils.objToString(null));
+ assertEquals("Test String", StringUtils.objToString("Test String"));
+
+ // assert byte buffer
+ ByteBuffer byteBuffer1 = ByteBuffer.wrap("1234".getBytes());
+ ByteBuffer byteBuffer2 = ByteBuffer.wrap("5678".getBytes());
+ // assert equal because ByteBuffer has overwritten the toString to return a summary string
+ assertEquals(byteBuffer1.toString(), byteBuffer2.toString());
+ // assert not equal
+ assertNotEquals(StringUtils.objToString(byteBuffer1), StringUtils.objToString(byteBuffer2));
+ }
+
@Test
public void testStringEmptyToNull() {
assertNull(StringUtils.emptyToNull(""));