kfaraz commented on code in PR #16846:
URL: https://github.com/apache/druid/pull/16846#discussion_r1704993205


##########
server/src/test/java/org/apache/druid/client/indexing/ClientCompactionRunnerInfoTest.java:
##########
@@ -148,6 +148,49 @@ public void 
testMSQEngineWithRollupFalseWithMetricsSpecIsInvalid()
     );
   }
 
+  @Test
+  public void testMSQEngineWithRollupTrueWithoutMetricsSpecIsInvalid()
+  {
+    DataSourceCompactionConfig compactionConfig = createCompactionConfig(
+        new DynamicPartitionsSpec(3, null),
+        Collections.emptyMap(),
+        new UserCompactionTaskGranularityConfig(null, null, true),
+        null
+    );
+    CompactionConfigValidationResult validationResult = 
ClientCompactionRunnerInfo.validateCompactionConfig(
+        compactionConfig,
+        CompactionEngine.NATIVE
+    );
+    Assert.assertFalse(validationResult.isValid());
+    Assert.assertEquals(
+        "MSQ: 'granularitySpec.rollup' must be false if 'metricsSpec' is null",
+        validationResult.getReason()
+    );
+  }
+
+  @Test
+  public void testMSQEngineWithUnsupportedMetricsSpecIsInValid()
+  {
+    // Aggregators having combiningFactory different from the 
aggregatorFactory are unsupported.
+    final String inputColName = "added";
+    final String outputColName = "sum_added";
+    DataSourceCompactionConfig compactionConfig = createCompactionConfig(

Review Comment:
   Please rename the method `createCompactionConfig` to 
`createMSQCompactionConfig` to avoid confusion.



##########
server/src/main/java/org/apache/druid/client/indexing/ClientCompactionRunnerInfo.java:
##########
@@ -160,6 +163,10 @@ public static CompactionConfigValidationResult 
validateRollupForMSQ(
       return CompactionConfigValidationResult.failure(
           "MSQ: 'granularitySpec.rollup' must be true if 'metricsSpec' is 
specified"
       );
+    } else if (metricsSpec == null && isRollup != null && isRollup) {

Review Comment:
   What about empty `metricsSpec`? I guess `rollup` must be false in that case 
too.



##########
server/src/test/java/org/apache/druid/client/indexing/ClientCompactionRunnerInfoTest.java:
##########
@@ -148,6 +148,49 @@ public void 
testMSQEngineWithRollupFalseWithMetricsSpecIsInvalid()
     );
   }
 
+  @Test
+  public void testMSQEngineWithRollupTrueWithoutMetricsSpecIsInvalid()
+  {
+    DataSourceCompactionConfig compactionConfig = createCompactionConfig(
+        new DynamicPartitionsSpec(3, null),
+        Collections.emptyMap(),
+        new UserCompactionTaskGranularityConfig(null, null, true),
+        null
+    );
+    CompactionConfigValidationResult validationResult = 
ClientCompactionRunnerInfo.validateCompactionConfig(
+        compactionConfig,
+        CompactionEngine.NATIVE
+    );
+    Assert.assertFalse(validationResult.isValid());
+    Assert.assertEquals(
+        "MSQ: 'granularitySpec.rollup' must be false if 'metricsSpec' is null",
+        validationResult.getReason()
+    );
+  }
+
+  @Test
+  public void testMSQEngineWithUnsupportedMetricsSpecIsInValid()
+  {
+    // Aggregators having combiningFactory different from the 
aggregatorFactory are unsupported.
+    final String inputColName = "added";
+    final String outputColName = "sum_added";
+    DataSourceCompactionConfig compactionConfig = createCompactionConfig(
+        new DynamicPartitionsSpec(3, null),
+        Collections.emptyMap(),
+        new UserCompactionTaskGranularityConfig(null, null, null),
+        new AggregatorFactory[]{new LongSumAggregatorFactory(outputColName, 
inputColName)}

Review Comment:
   Can we add a test for a valid aggregator factory too (unless it already 
exists)?



##########
server/src/main/java/org/apache/druid/client/indexing/ClientCompactionRunnerInfo.java:
##########
@@ -174,11 +181,30 @@ public static CompactionConfigValidationResult 
validateMaxNumTasksForMSQ(Map<Str
                                     
.getInt(ClientMSQContext.CTX_MAX_NUM_TASKS, 
ClientMSQContext.DEFAULT_MAX_NUM_TASKS);
       if (maxNumTasks < 2) {
         return CompactionConfigValidationResult.failure(
-            "MSQ: Context maxNumTasks[%,d] must be at least 2 (1 controller + 
1 worker)",
+            "MSQ: Context 'maxNumTasks'[%,d] must be at least 2 (1 controller 
+ 1 worker)",
             maxNumTasks
         );
       }
     }
     return CompactionConfigValidationResult.success();
   }
+
+  /**
+   * Validate each metric is idempotent, i.e. it defines some 
aggregatorFactory 'A' s.t. 'A = A.combiningFactory()'.
+   */
+  public static CompactionConfigValidationResult 
validateMetricsSpecForMSQ(AggregatorFactory[] metricsSpec)
+  {
+    if (metricsSpec == null) {
+      return CompactionConfigValidationResult.success();
+    }
+    return Arrays.stream(metricsSpec)
+                 .filter(aggregatorFactory ->
+                             
!aggregatorFactory.equals(aggregatorFactory.getCombiningFactory()))
+                 .findFirst()
+                 .map(aggregatorFactory ->
+                          CompactionConfigValidationResult.failure(
+                              "MSQ: Non-idempotent aggregator[%s] not 
supported in 'metricsSpec'.",
+                              aggregatorFactory.getName()
+                          
)).orElse(CompactionConfigValidationResult.success());

Review Comment:
   Style: the `orElse` should align with the `map`
   ```suggestion
                    .map(
                       aggregatorFactory ->
                             CompactionConfigValidationResult.failure(
                                 "MSQ: Non-idempotent aggregator[%s] not 
supported in 'metricsSpec'.",
                                 aggregatorFactory.getName()
                             )
                      ).orElse(CompactionConfigValidationResult.success());
   ```



##########
extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/indexing/MSQCompactionRunnerTest.java:
##########
@@ -345,48 +377,6 @@ public void 
testMSQControllerTaskSpecWithAggregatorsIsValid() throws JsonProcess
     Assert.assertEquals(WorkerAssignmentStrategy.MAX, 
actualMSQSpec.getAssignmentStrategy());
   }
 
-  @Test
-  public void 
testIntervalsWithRolledUpSegmentsAndNonIdempotentAggregatorFails()

Review Comment:
   Shouldn't we still have this test i.e. a non idempotent aggregator should 
continue to fail, right?



##########
server/src/main/java/org/apache/druid/client/indexing/ClientCompactionRunnerInfo.java:
##########
@@ -174,11 +181,30 @@ public static CompactionConfigValidationResult 
validateMaxNumTasksForMSQ(Map<Str
                                     
.getInt(ClientMSQContext.CTX_MAX_NUM_TASKS, 
ClientMSQContext.DEFAULT_MAX_NUM_TASKS);
       if (maxNumTasks < 2) {
         return CompactionConfigValidationResult.failure(
-            "MSQ: Context maxNumTasks[%,d] must be at least 2 (1 controller + 
1 worker)",
+            "MSQ: Context 'maxNumTasks'[%,d] must be at least 2 (1 controller 
+ 1 worker)",
             maxNumTasks
         );
       }
     }
     return CompactionConfigValidationResult.success();
   }
+
+  /**
+   * Validate each metric is idempotent, i.e. it defines some 
aggregatorFactory 'A' s.t. 'A = A.combiningFactory()'.
+   */
+  public static CompactionConfigValidationResult 
validateMetricsSpecForMSQ(AggregatorFactory[] metricsSpec)
+  {
+    if (metricsSpec == null) {
+      return CompactionConfigValidationResult.success();
+    }
+    return Arrays.stream(metricsSpec)
+                 .filter(aggregatorFactory ->
+                             
!aggregatorFactory.equals(aggregatorFactory.getCombiningFactory()))

Review Comment:
   Nit: can be in a single line



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