xiangfu0 commented on code in PR #19905:
URL: https://github.com/apache/pinot/pull/19905#discussion_r4296610807


##########
pinot-core/src/test/java/org/apache/pinot/core/query/aggregation/function/AnyValueGroupByRecomputationTest.java:
##########
@@ -0,0 +1,103 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.core.query.aggregation.function;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.pinot.common.request.context.ExpressionContext;
+import org.apache.pinot.core.common.BlockValSet;
+import org.apache.pinot.core.query.aggregation.groupby.GroupByResultHolder;
+import org.apache.pinot.spi.data.FieldSpec.DataType;
+import org.apache.pinot.spi.utils.ByteArray;
+import org.testng.annotations.Test;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockingDetails;
+import static org.mockito.Mockito.when;
+import static org.testng.Assert.assertEquals;
+
+
+/// Counts how many times ANY_VALUE group-by reads the values of a 
non-dictionary input per block.
+///
+/// A transform input (for example `jsonExtractScalar`) recomputes the whole 
block on every `get*ValuesSV()` call,
+/// so the number of calls per block multiplies the transform cost.
+public class AnyValueGroupByRecomputationTest {
+  private static final int NUM_DOCS = 1000;
+
+  @Test
+  public void testGroupByReadsNonDictionaryStringValuesOncePerBlock() {
+    String[] values = new String[NUM_DOCS];
+    for (int i = 0; i < NUM_DOCS; i++) {
+      values[i] = "zone-" + (i % 3);
+    }
+    BlockValSet valueSet = mockNonDictionaryValueSet(DataType.STRING);
+    when(valueSet.getStringValuesSV()).thenReturn(values);
+
+    GroupByResultHolder holder = aggregateGroupBy(valueSet);
+
+    assertEquals(countCalls(valueSet, "getStringValuesSV"), 1,
+        "getStringValuesSV() must be called once per block, not once per row");
+    for (int i = 0; i < NUM_DOCS; i++) {
+      assertEquals(holder.<String>getResult(i), values[i]);
+    }
+  }
+
+  @Test
+  public void testGroupByReadsNonDictionaryBytesValuesOncePerBlock() {
+    byte[][] values = new byte[NUM_DOCS][];
+    for (int i = 0; i < NUM_DOCS; i++) {
+      values[i] = new byte[]{(byte) i, (byte) (i >> 8)};
+    }
+    BlockValSet valueSet = mockNonDictionaryValueSet(DataType.BYTES);
+    when(valueSet.getBytesValuesSV()).thenReturn(values);
+
+    GroupByResultHolder holder = aggregateGroupBy(valueSet);
+
+    assertEquals(countCalls(valueSet, "getBytesValuesSV"), 1,

Review Comment:
   Nice to see the BYTES path covered — it's the one `getDirectValueReader` 
branch that allocates (wraps in `ByteArray`), so asserting both the single read 
and the `ByteArray` wrapping here is exactly the right check.



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