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
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static String getPartitionPathFromGenericRecord(GenericRecord genericReco
public static String[] extractRecordKeys(String recordKey) {
String[] fieldKV = recordKey.split(",");
return Arrays.stream(fieldKV).map(kv -> {
final String[] kvArray = kv.split(":");
final String[] kvArray = kv.split(":", 2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is needed when the value contains a colon (:). Could you add a unit test for that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was referring to the same case and asking for adding a unit test in the repo. I added a unit for this PR. Will land it once CI passes.

if (kvArray.length == 1) {
return kvArray[0];
} else if (kvArray[1].equals(NULL_RECORDKEY_PLACEHOLDER)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,19 @@ public class TestKeyGenUtils {
public void testExtractRecordKeys() {
// test complex key form: field1:val1,field2:val2,...
String[] s1 = KeyGenUtils.extractRecordKeys("id:1");
Assertions.assertArrayEquals(new String[]{"1"}, s1);
Assertions.assertArrayEquals(new String[] {"1"}, s1);

String[] s2 = KeyGenUtils.extractRecordKeys("id:1,id:2");
Assertions.assertArrayEquals(new String[]{"1", "2"}, s2);
Assertions.assertArrayEquals(new String[] {"1", "2"}, s2);

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

String[] s4 = KeyGenUtils.extractRecordKeys("id:ab:cd,id2:ef");
Assertions.assertArrayEquals(new String[] {"ab:cd", "ef"}, s4);

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