danny0405 commented on code in PR #13650:
URL: https://github.com/apache/hudi/pull/13650#discussion_r2357253339


##########
hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/keygen/BuiltinKeyGenerator.java:
##########
@@ -238,20 +238,39 @@ private <S> S combineCompositeRecordKeyInternal(
       Predicate<S> isNullOrEmptyKeyPartPredicate,
       Object... recordKeyParts
   ) {
-    boolean hasNonNullNonEmptyPart = false;
+    if (recordKeyParts.length == 0) {
+      throw new HoodieKeyException(String.format("All of the values for (%s) 
were either null or empty", recordKeyFields));
+    }
 
     PartitionPathFormatterBase.StringBuilder<S> sb = builderFactory.get();
-    for (int i = 0; i < recordKeyParts.length; ++i) {
+
+    if (recordKeyParts.length == 1) {
       // NOTE: If record-key part has already been a string [[toString]] will 
be a no-op
-      S convertedKeyPart = 
emptyKeyPartHandler.apply(converter.apply(recordKeyParts[i]));
+      S convertedKeyPart = 
emptyKeyPartHandler.apply(converter.apply(recordKeyParts[0]));
 
-      if (encodeSingleKeyFieldName || recordKeyParts.length > 1) {
-        sb.appendJava(recordKeyFields.get(i));
+      if (encodeSingleKeyFieldName) {
+        sb.appendJava(recordKeyFields.get(0));
         sb.appendJava(DEFAULT_COLUMN_VALUE_SEPARATOR);
       }
       sb.append(convertedKeyPart);
       // This check is to validate that overall composite-key has at least one 
non-null, non-empty
       // segment
+      if (isNullOrEmptyKeyPartPredicate.test(convertedKeyPart)) {
+        throw new HoodieKeyException(String.format("All of the values for (%s) 
were either null or empty", recordKeyFields));
+      }
+      return sb.build();
+    }
+
+    boolean hasNonNullNonEmptyPart = false;
+    for (int i = 0; i < recordKeyParts.length; ++i) {
+      // NOTE: If record-key part has already been a string [[toString]] will 
be a no-op
+      S convertedKeyPart = 
emptyKeyPartHandler.apply(converter.apply(recordKeyParts[i]));
+
+      sb.appendJava(recordKeyFields.get(i));
+      sb.appendJava(DEFAULT_COLUMN_VALUE_SEPARATOR);
+      sb.append(convertedKeyPart);
+      // This check is to validate that overall composite-key has at least one 
non-null, non-empty
+      // segment

Review Comment:
   it's for efficiency, the for-loop is not necessary for most of the cases.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to