Skip to content

Commit

Permalink
[HUDI-4336] Fix records overwritten bug with binary primary key (#5996)
Browse files Browse the repository at this point in the history
  • Loading branch information
luoyajun authored Jun 30, 2022
1 parent 03a94d9 commit 3948b89
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -88,7 +89,10 @@ public static String nullToEmpty(@Nullable String string) {
}

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();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.junit.jupiter.api.Test;

import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;

Expand Down Expand Up @@ -51,6 +52,20 @@ public void testStringNullToEmpty() {
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(""));
Expand Down

0 comments on commit 3948b89

Please sign in to comment.