xiangfu0 commented on code in PR #19905:
URL: https://github.com/apache/pinot/pull/19905#discussion_r4296091737
##########
pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/AnyValueAggregationFunction.java:
##########
@@ -197,10 +198,12 @@ private void aggregateHelper(int length, BlockValSet bvs,
ValueProcessor<Object>
}
});
} else {
- // Fall back to direct value access based on type
+ // Fall back to direct value access based on type. Read the values once
per block: for a transform input, each
+ // get*ValuesSV() call evaluates the transform on the whole block again.
+ IntFunction<Object> valueReader = getDirectValueReader(bvs);
Review Comment:
Small behavior note, not a blocker: the reader is now built unconditionally
before `forEachNotNull`, so an all-null or zero-length block now evaluates the
transform exactly once, whereas before `getDirectValue` was never reached in
that case. That's strictly better than the old N-times cost and still correct,
just worth being aware of.
##########
pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/AnyValueAggregationFunction.java:
##########
@@ -231,23 +234,38 @@ private Object getDictionaryValue(Dictionary dict, int
dictId, DataType storedTy
}
}
- /// Get value directly from BlockValSet based on data type
- private Object getDirectValue(BlockValSet bvs, int index) {
+ /// Returns a reader for the values of the BlockValSet based on data type.
The values are read once, when this method
+ /// is called.
+ private IntFunction<Object> getDirectValueReader(BlockValSet bvs) {
Review Comment:
The BYTES branch allocates a fresh `ByteArray` per row inside the lambda,
which matches the old behavior exactly, so no concern there. The one gap is
that only the STRING branch is covered by a test; a quick BYTES case would
guard this wrapping path since it is the one branch that does more than a plain
array index.
##########
pinot-core/src/test/java/org/apache/pinot/core/query/aggregation/function/AnyValueGroupByRecomputationTest.java:
##########
@@ -0,0 +1,70 @@
+/**
+ * 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.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 testGroupByReadsNonDictionaryValuesOncePerBlock() {
+ ExpressionContext expression =
ExpressionContext.forIdentifier("jsonExtractResult");
+ AnyValueAggregationFunction function = new
AnyValueAggregationFunction(List.of(expression), false);
+
+ String[] values = new String[NUM_DOCS];
+ int[] groupKeys = new int[NUM_DOCS];
+ for (int i = 0; i < NUM_DOCS; i++) {
+ values[i] = "zone-" + (i % 3);
+ groupKeys[i] = i;
+ }
+ BlockValSet valueSet = mock(BlockValSet.class);
+ when(valueSet.getValueType()).thenReturn(DataType.STRING);
+ when(valueSet.isDictionaryEncoded()).thenReturn(false);
+ when(valueSet.isSingleValue()).thenReturn(true);
Review Comment:
This `isSingleValue()` stub looks unused for the ANY_VALUE SV path, which
does not consult it. You can likely drop it to keep the mock setup minimal,
though it is harmless either way.
--
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]