kfaraz commented on a change in pull request #11848:
URL: https://github.com/apache/druid/pull/11848#discussion_r742542456



##########
File path: 
indexing-service/src/main/java/org/apache/druid/indexing/common/task/batch/parallel/iterator/RangePartitionIndexTaskInputRowIteratorBuilder.java
##########
@@ -79,36 +80,46 @@ public HandlingInputRowIterator build()
   }
 
   private static HandlingInputRowIterator.InputRowHandler 
createOnlySingleDimensionValueRowsHandler(
-      String partitionDimension
+      List<String> partitionDimensions
   )
   {
-    return inputRow -> {
-      int dimensionValueCount = getSingleOrNullDimensionValueCount(inputRow, 
partitionDimension);
-      return dimensionValueCount != 1;
-    };
+    return inputRow -> isRowHandled(inputRow, partitionDimensions, 
dimValueCount -> dimValueCount != 1);
   }
 
   private static HandlingInputRowIterator.InputRowHandler 
createOnlySingleOrNullDimensionValueRowsHandler(
-      String partitionDimension
+      List<String> partitionDimensions
   )
   {
-    return inputRow -> {
-      int dimensionValueCount = getSingleOrNullDimensionValueCount(inputRow, 
partitionDimension);
-      return dimensionValueCount > 1;  // Rows.objectToStrings() returns an 
empty list for a single null value
-    };
+    // Rows.objectToStrings() returns an empty list for a single null value
+    return inputRow -> isRowHandled(inputRow, partitionDimensions, 
dimValueCount -> dimValueCount > 1);
   }
 
-  private static int getSingleOrNullDimensionValueCount(InputRow inputRow, 
String partitionDimension)
+  /**
+   * @param valueCountPredicate Predicate that must be satisfied
+   *                            for atleast one of the partitionDimensions for 
the row to be marked as handled.
+   * @return true when the given InputRow should be marked handled
+   * and need not be processed further.
+   */
+  private static boolean isRowHandled(
+      InputRow inputRow,
+      List<String> partitionDimensions,
+      Predicate<Integer> valueCountPredicate
+  )
   {
-    List<String> dimensionValues = inputRow.getDimension(partitionDimension);
-    int dimensionValueCount = dimensionValues.size();
-    if (dimensionValueCount > 1) {
-      throw new IAE(
-          "Cannot partition on multi-value dimension [%s] for input row [%s]",
-          partitionDimension,
-          inputRow
-      );
+    for (String dimension : partitionDimensions) {
+      int dimensionValueCount = inputRow.getDimension(dimension).size();
+      if (dimensionValueCount > 1) {
+        throw new IAE(
+            "Cannot partition on multi-value dimension [%s] for input row 
[%s]",
+            dimension,
+            inputRow
+        );
+      } else if (valueCountPredicate.test(dimensionValueCount)) {

Review comment:
       Refactored this logic to have two methods:
   - `ensureNoMultiValueDimensions()` which checks for multiple values and 
throws IAE
   - `hasEmptyDimensions()`




-- 
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]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to