This is an automated email from the ASF dual-hosted git repository.

danny0405 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 7e9ad05317 [minor] following HUDI-4739, fix the extraction for simple 
record keys (#6594)
7e9ad05317 is described below

commit 7e9ad053173ea0883503750918d93ab2fff0e6db
Author: Danny Chan <[email protected]>
AuthorDate: Tue Sep 6 09:36:15 2022 +0800

    [minor] following HUDI-4739, fix the extraction for simple record keys 
(#6594)
---
 .../src/main/java/org/apache/hudi/keygen/KeyGenUtils.java            | 4 +++-
 .../src/test/java/org/apache/hudi/keygen/TestKeyGenUtils.java        | 5 +++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git 
a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/keygen/KeyGenUtils.java
 
b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/keygen/KeyGenUtils.java
index 1fd46d31e5..fa3c212ee0 100644
--- 
a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/keygen/KeyGenUtils.java
+++ 
b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/keygen/KeyGenUtils.java
@@ -75,7 +75,9 @@ public class KeyGenUtils {
     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 "";
diff --git 
a/hudi-client/hudi-client-common/src/test/java/org/apache/hudi/keygen/TestKeyGenUtils.java
 
b/hudi-client/hudi-client-common/src/test/java/org/apache/hudi/keygen/TestKeyGenUtils.java
index 06a6fcd7d7..82ea37e90b 100644
--- 
a/hudi-client/hudi-client-common/src/test/java/org/apache/hudi/keygen/TestKeyGenUtils.java
+++ 
b/hudi-client/hudi-client-common/src/test/java/org/apache/hudi/keygen/TestKeyGenUtils.java
@@ -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);
 
@@ -33,5 +34,9 @@ public class TestKeyGenUtils {
 
     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);
   }
 }

Reply via email to