Copilot commented on code in PR #18648:
URL: https://github.com/apache/pinot/pull/18648#discussion_r3338572856


##########
pinot-query-runtime/src/test/java/org/apache/pinot/query/runtime/operator/LeafOperatorTest.java:
##########
@@ -408,6 +415,44 @@ void execute() {
     operator.close();
   }
 
+  @Test
+  public void shouldPropagateDistinctEarlyTerminationReason() {
+    // Given:
+    QueryContext queryContext = 
QueryContextConverterUtils.getQueryContext("SELECT DISTINCT intCol FROM tbl");
+    DataSchema schema = new DataSchema(new String[]{"intCol"},
+        new DataSchema.ColumnDataType[]{DataSchema.ColumnDataType.INT});
+    InstanceResponseBlock metadataBlock = new InstanceResponseBlock(new 
MetadataResultsBlock());
+    
metadataBlock.getResponseMetadata().put(DataTable.MetadataKey.EARLY_TERMINATION_REASON.getName(),
+        EarlyTerminationReason.DISTINCT_MAX_ROWS.name());
+    QueryExecutor queryExecutor = mockQueryExecutor(Collections.emptyList(), 
metadataBlock);
+    LeafOperator operator =
+        new LeafOperator(OperatorTestUtil.getTracingContext(), 
mockQueryRequests(1), schema, queryExecutor,
+            _executorService);
+    _operatorRef.set(operator);
+
+    // When:
+    assertTrue(operator.nextBlock().isEos(), "Expected EOS after reading the 
metadata block");
+
+    // Then:
+    StatMap<LeafOperator.StatKey> leafStats = operator.copyStatMaps();
+    
assertEquals(leafStats.getString(LeafOperator.StatKey.EARLY_TERMINATION_REASONS),
+        EarlyTerminationReason.DISTINCT_MAX_ROWS.name());
+
+    BrokerResponseNativeV2 brokerResponse = new BrokerResponseNativeV2();
+    MultiStageOperator.Type.LEAF.mergeInto(brokerResponse, leafStats);
+    assertEquals(brokerResponse.getEarlyTerminationReasons(), 
List.of(EarlyTerminationReason.DISTINCT_MAX_ROWS.name()));
+    assertTrue(brokerResponse.isPartialResult());
+    JsonNode responseJson = JsonUtils.objectToJsonNode(brokerResponse);
+    assertEquals(responseJson.path("earlyTerminationReasons").get(0).asText(),
+        EarlyTerminationReason.DISTINCT_MAX_ROWS.name());

Review Comment:
   `responseJson.path("earlyTerminationReasons").get(0)` can return null when 
the field is missing or not an array, causing this test to fail with an NPE 
instead of a clear assertion failure. Using `path(0)` avoids nulls and keeps 
the failure signal focused on the assertion.



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