weixiangsun commented on a change in pull request #7584:
URL: https://github.com/apache/pinot/pull/7584#discussion_r733939548



##########
File path: 
pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/LastDoubleValueWithTimeAggregationFunction.java
##########
@@ -0,0 +1,127 @@
+/**
+ * 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.Arrays;
+import java.util.List;
+import org.apache.pinot.common.request.context.ExpressionContext;
+import org.apache.pinot.common.utils.DataSchema.ColumnDataType;
+import org.apache.pinot.core.common.BlockValSet;
+import org.apache.pinot.core.common.ObjectSerDeUtils;
+import org.apache.pinot.core.query.aggregation.AggregationResultHolder;
+import org.apache.pinot.core.query.aggregation.groupby.GroupByResultHolder;
+import org.apache.pinot.segment.local.customobject.DoubleValueTimePair;
+import org.apache.pinot.segment.local.customobject.ValueTimePair;
+
+/**
+ * This function is used for LastWithTime calculations for data column with 
double type.
+ * <p>The function can be used as LastWithTime(dataExpression, timeExpression, 
'double')
+ * <p>Following arguments are supported:
+ * <ul>
+ *   <li>dataExpression: expression that contains the double data column to be 
calculated last on</li>
+ *   <li>timeExpression: expression that contains the column to be used to 
decide which data is last, can be any
+ *   Numeric column</li>
+ * </ul>
+ */
+@SuppressWarnings({"rawtypes", "unchecked"})
+public class LastDoubleValueWithTimeAggregationFunction extends 
LastWithTimeAggregationFunction<Double> {
+
+  private final static ValueTimePair<Double> DEFAULT_VALUE_TIME_PAIR
+          = new DoubleValueTimePair(Double.NaN, Long.MIN_VALUE);
+
+  public LastDoubleValueWithTimeAggregationFunction(
+          ExpressionContext dataCol,
+          ExpressionContext timeCol,
+          ObjectSerDeUtils.ObjectSerDe<? extends ValueTimePair<Double>> 
objectSerDe) {
+    super(dataCol, timeCol, objectSerDe);
+  }
+
+  @Override
+  public List<ExpressionContext> getInputExpressions() {
+    return Arrays.asList(_expression, _timeCol, 
ExpressionContext.forLiteral("Long"));
+  }
+
+  @Override
+  public ValueTimePair<Double> constructValueTimePair(Double value, long time) 
{
+    return new DoubleValueTimePair(value, time);
+  }
+
+  @Override
+  public ValueTimePair<Double> getDefaultValueTimePair() {
+    return DEFAULT_VALUE_TIME_PAIR;
+  }
+
+  @Override
+  public void updateResultWithRawData(int length, AggregationResultHolder 
aggregationResultHolder,
+                                             BlockValSet blockValSet, 
BlockValSet timeValSet) {
+    ValueTimePair<Double> defaultValueTimePair = getDefaultValueTimePair();
+    Double lastData = defaultValueTimePair.getValue();
+    long lastTime = defaultValueTimePair.getTime();
+    double [] doubleValues = blockValSet.getDoubleValuesSV();
+    long[] timeValues = timeValSet.getLongValuesSV();
+    for (int i = 0; i < length; i++) {
+      double data = doubleValues[i];
+      long time = timeValues[i];
+      if (time >= lastTime) {
+        lastTime = time;
+        lastData = data;
+      }
+    }
+    setAggregationResult(aggregationResultHolder, lastData, lastTime);
+  }
+
+  @Override
+  public void updateGroupResultWithRawDataSv(int length, int[] groupKeyArray, 
GroupByResultHolder groupByResultHolder,
+                                             BlockValSet blockValSet, 
BlockValSet timeValSet) {
+    double[] doubleValues = blockValSet.getDoubleValuesSV();
+    long[] timeValues = timeValSet.getLongValuesSV();
+    for (int i = 0; i < length; i++) {
+      double data = doubleValues[i];
+      long time = timeValues[i];
+      setGroupByResult(groupKeyArray[i], groupByResultHolder, data, time);
+    }
+  }
+
+  @Override
+  public void updateGroupResultWithRawDataMv(int length,
+                                             int[][] groupKeysArray,
+                                             GroupByResultHolder 
groupByResultHolder,
+                                             BlockValSet blockValSet,
+                                             BlockValSet timeValSet) {
+    double[] doubleValues = blockValSet.getDoubleValuesSV();
+    long[] timeValues = timeValSet.getLongValuesSV();
+    for (int i = 0; i < length; i++) {
+      double value = doubleValues[i];
+      long time = timeValues[i];
+      for (int groupKey : groupKeysArray[i]) {
+        setGroupByResult(groupKey, groupByResultHolder, value, time);
+      }
+    }
+  }
+
+  @Override
+  public String getResultColumnName() {
+    return getType().getName().toLowerCase() + "(" + _expression + "," + 
_timeCol + ", Double)";

Review comment:
       Done




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