You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2022/02/08 17:30:25 UTC

[GitHub] [pinot] Jackie-Jiang commented on a change in pull request #8139: Aggregation delay conversion to double

Jackie-Jiang commented on a change in pull request #8139:
URL: https://github.com/apache/pinot/pull/8139#discussion_r801886101



##########
File path: pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/MinAggregationFunction.java
##########
@@ -54,15 +54,47 @@ public GroupByResultHolder createGroupByResultHolder(int initialCapacity, int ma
   @Override
   public void aggregate(int length, AggregationResultHolder aggregationResultHolder,
       Map<ExpressionContext, BlockValSet> blockValSetMap) {
-    double[] valueArray = blockValSetMap.get(_expression).getDoubleValuesSV();
-    double min = aggregationResultHolder.getDoubleResult();
-    for (int i = 0; i < length; i++) {
-      double value = valueArray[i];
-      if (value < min) {
-        min = value;
+    BlockValSet blockValSet = blockValSetMap.get(_expression);
+    switch (blockValSet.getValueType().getStoredType()) {
+      case INT: {
+        int[] values = blockValSet.getIntValuesSV();
+        int min = values[0];
+        for (int i = 0; i < length & i < values.length; i++) {
+          min = Math.min(values[i], min);
+        }
+        aggregationResultHolder.setValue(Math.min(min, aggregationResultHolder.getDoubleResult()));
+        break;
+      }
+      case LONG: {
+        long[] values = blockValSet.getLongValuesSV();
+        long min = values[0];
+        for (int i = 0; i < length & i < values.length; i++) {
+          min = Math.min(values[i], min);
+        }
+        aggregationResultHolder.setValue(Math.min(min, aggregationResultHolder.getDoubleResult()));
+        break;
+      }
+      case FLOAT: {
+        float[] values = blockValSet.getFloatValuesSV();
+        float min = values[0];
+        for (int i = 0; i < length & i < values.length; i++) {
+          min = Math.min(values[i], min);
+        }
+        aggregationResultHolder.setValue(Math.min(min, aggregationResultHolder.getDoubleResult()));
+        break;
+      }
+      case DOUBLE: {
+        double[] values = blockValSet.getDoubleValuesSV();
+        double min = values[0];
+        for (int i = 0; i < length & i < values.length; i++) {
+          min = Math.min(values[i], min);
+        }
+        aggregationResultHolder.setValue(Math.min(min, aggregationResultHolder.getDoubleResult()));
+        break;
       }
+      default:
+        throw new IllegalStateException("Cannot compute min for non-numeric type: " + blockValSet.getValueType());

Review comment:
       Fix the exception message to reflect the correct aggregation

##########
File path: pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/SumAggregationFunction.java
##########
@@ -54,10 +54,39 @@ public GroupByResultHolder createGroupByResultHolder(int initialCapacity, int ma
   @Override
   public void aggregate(int length, AggregationResultHolder aggregationResultHolder,
       Map<ExpressionContext, BlockValSet> blockValSetMap) {
-    double[] valueArray = blockValSetMap.get(_expression).getDoubleValuesSV();
     double sum = aggregationResultHolder.getDoubleResult();
-    for (int i = 0; i < length; i++) {
-      sum += valueArray[i];
+    BlockValSet blockValSet = blockValSetMap.get(_expression);
+    switch (blockValSet.getValueType().getStoredType()) {
+      case INT: {
+        int[] values = blockValSet.getIntValuesSV();
+        for (int i = 0; i < length & i < values.length; i++) {
+          sum += values[i];
+        }
+        break;
+      }
+      case LONG: {
+        long[] values = blockValSet.getLongValuesSV();
+        for (int i = 0; i < length & i < values.length; i++) {
+          sum += values[i];
+        }
+        break;
+      }
+      case FLOAT: {
+        float[] values = blockValSet.getFloatValuesSV();
+        for (int i = 0; i < length & i < values.length; i++) {
+          sum += values[i];
+        }
+        break;
+      }
+      case DOUBLE: {
+        double[] values = blockValSet.getDoubleValuesSV();
+        for (int i = 0; i < length & i < values.length; i++) {
+          sum += values[i];
+        }
+        break;
+      }
+      default:
+        throw new IllegalStateException("Cannot compute min for non-numeric type: " + blockValSet.getValueType());

Review comment:
       Fix the exception message to reflect the correct aggregation




-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org