yashmayya commented on code in PR #17063:
URL: https://github.com/apache/pinot/pull/17063#discussion_r2456832365


##########
pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/AggregationFunctionType.java:
##########
@@ -62,7 +62,7 @@ public enum AggregationFunctionType {
   SUMINT("sumInt", ReturnTypes.AGG_SUM, OperandTypes.INTEGER),
   SUMLONG("sumLong", ReturnTypes.AGG_SUM, 
OperandTypes.or(OperandTypes.INTEGER, OperandTypes.ARRAY_OF_INTEGER)),
   SUMPRECISION("sumPrecision", ReturnTypes.explicit(SqlTypeName.DECIMAL), 
OperandTypes.ANY, SqlTypeName.OTHER),
-  AVG("avg", SqlTypeName.OTHER, SqlTypeName.DOUBLE),
+  AVG("avg", ReturnTypes.DOUBLE, OperandTypes.or(OperandTypes.NUMERIC, 
OperandTypes.ARRAY), SqlTypeName.OTHER),

Review Comment:
   ```suggestion
     AVG("avg", ReturnTypes.DOUBLE, OperandTypes.or(OperandTypes.NUMERIC, 
OperandTypes.ARRAY), SqlTypeName.OTHER, SqlTypeName.DOUBLE),
   ```
   
   We should retain the final return type 



##########
pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/AvgAggregationFunction.java:
##########
@@ -152,6 +188,49 @@ public void aggregateGroupByMV(int length, int[][] 
groupKeysArray, GroupByResult
           }
         }
       });
+      return;
+    }
+
+    if (blockValSet.isSingleValue()) {
+      aggregateSvGroupByMv(blockValSet, length, groupKeysArray, 
groupByResultHolder);
+    } else {
+      aggregateMvGroupByMv(blockValSet, length, groupKeysArray, 
groupByResultHolder);
+    }
+  }
+
+  private void aggregateSvGroupByMv(BlockValSet blockValSet, int length, 
int[][] groupKeysArray,
+      GroupByResultHolder groupByResultHolder) {
+    double[] doubleValues = blockValSet.getDoubleValuesSV();
+    forEachNotNull(length, blockValSet, (from, to) -> {
+      for (int i = from; i < to; i++) {
+        for (int groupKey : groupKeysArray[i]) {
+          updateGroupByResult(groupKey, groupByResultHolder, doubleValues[i], 
1L);
+        }
+      }
+    });
+  }
+
+  private void aggregateMvGroupByMv(BlockValSet blockValSet, int length, 
int[][] groupKeysArray,

Review Comment:
   Let's add some basic tests for these scenarios in 
`AvgAggregationFunctionTest`?



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