Jackie-Jiang commented on code in PR #20108:
URL: https://github.com/apache/pinot/pull/20108#discussion_r4448622027


##########
pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/array/SumArrayLongAggregationFunction.java:
##########
@@ -106,64 +100,69 @@ public void aggregateGroupByMV(int length, int[][] 
groupKeysArray, GroupByResult
   }
 
   private void setGroupByResult(GroupByResultHolder groupByResultHolder, 
long[] values, int groupKey) {
-    LongArrayList sumList = groupByResultHolder.getResult(groupKey);
-    if (sumList == null) {
-      sumList = new LongArrayList();
-      groupByResultHolder.setValueForKey(groupKey, sumList);
+    long[] sums = groupByResultHolder.getResult(groupKey);
+    long[] newSums = add(sums, values);
+    if (newSums != sums) {
+      groupByResultHolder.setValueForKey(groupKey, newSums);
     }
-    aggregateMerge(values, sumList);
   }
 
-  private void aggregateMerge(long[] values, LongArrayList sumList) {
-    for (int j = sumList.size(); j < values.length; j++) {
-      sumList.add(0L);
+  /// Adds the values to the sums and returns the sums, which is a new array 
when there are none yet or the values are
+  /// longer.
+  private static long[] add(@Nullable long[] sums, long[] values) {
+    if (sums == null) {
+      return values.clone();
+    }
+    if (sums.length < values.length) {

Review Comment:
   Added `testSumArrayLongAddsArraysOfDifferentLengths` and 
`testSumArrayDoubleAddsArraysOfDifferentLengths` to 
`ValueAggregationNullHandlingTest` in 0a96931757. They feed your rows `{1}`, 
`{10, 20, 30}`, `{100, 200}` in twice, so the second block also adds arrays 
shorter than the running sums, and cover `aggregate`, `aggregateGroupBySV` and 
`aggregateGroupByMV`. They also call `merge` in both orders.
   



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