[HUDI-4336] Fix records overwritten bug with binary primary key (#5996)
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
package org.apache.hudi.common.util;
|
package org.apache.hudi.common.util;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -88,7 +89,10 @@ public class StringUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String objToString(@Nullable Object obj) {
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ package org.apache.hudi.common.util;
|
|||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
@@ -51,6 +52,20 @@ public class TestStringUtils {
|
|||||||
assertEquals("", StringUtils.nullToEmpty(null));
|
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
|
@Test
|
||||||
public void testStringEmptyToNull() {
|
public void testStringEmptyToNull() {
|
||||||
assertNull(StringUtils.emptyToNull(""));
|
assertNull(StringUtils.emptyToNull(""));
|
||||||
|
|||||||
Reference in New Issue
Block a user