Skip to content

Commit

Permalink
[minor] following HUDI-4739, fix the extraction for simple record keys (
Browse files Browse the repository at this point in the history
  • Loading branch information
danny0405 authored and fengjian committed Apr 5, 2023
1 parent 4e871d1 commit 98e7f06
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ public static String[] extractRecordKeys(String recordKey) {
String[] fieldKV = recordKey.split(",");
return Arrays.stream(fieldKV).map(kv -> {
final String[] kvArray = kv.split(":");
if (kvArray[1].equals(NULL_RECORDKEY_PLACEHOLDER)) {
if (kvArray.length == 1) {
return kvArray[0];
} else if (kvArray[1].equals(NULL_RECORDKEY_PLACEHOLDER)) {
return null;
} else if (kvArray[1].equals(EMPTY_RECORDKEY_PLACEHOLDER)) {
return "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class TestKeyGenUtils {

@Test
public void testExtractRecordKeys() {
// test complex key form: field1:val1,field2:val2,...
String[] s1 = KeyGenUtils.extractRecordKeys("id:1");
Assertions.assertArrayEquals(new String[]{"1"}, s1);

Expand All @@ -33,5 +34,9 @@ public void testExtractRecordKeys() {

String[] s3 = KeyGenUtils.extractRecordKeys("id:1,id2:__null__,id3:__empty__");
Assertions.assertArrayEquals(new String[]{"1", null, ""}, s3);

// test simple key form: val1
String[] s4 = KeyGenUtils.extractRecordKeys("1");
Assertions.assertArrayEquals(new String[]{"1"}, s4);
}
}

0 comments on commit 98e7f06

Please sign in to comment.