Jackie-Jiang commented on a change in pull request #7584: URL: https://github.com/apache/pinot/pull/7584#discussion_r736061696
########## File path: pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/LastDoubleValueWithTimeAggregationFunction.java ########## @@ -0,0 +1,126 @@ +/** + * 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 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.DoubleLongPair; +import org.apache.pinot.segment.local.customobject.ValueLongPair; + + +/** + * 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 ValueLongPair<Double> DEFAULT_VALUE_TIME_PAIR + = new DoubleLongPair(Double.NaN, Long.MIN_VALUE); + + public LastDoubleValueWithTimeAggregationFunction( + ExpressionContext dataCol, + ExpressionContext timeCol) { + super(dataCol, timeCol, ObjectSerDeUtils.DOUBLE_LONG_PAIR_SER_DE); + } + + @Override + public ValueLongPair<Double> constructValueLongPair(Double value, long time) { + return new DoubleLongPair(value, time); + } + + @Override + public ValueLongPair<Double> getDefaultValueTimePair() { + return DEFAULT_VALUE_TIME_PAIR; + } + + @Override + public void aggregateResultWithRawData(int length, AggregationResultHolder aggregationResultHolder, + BlockValSet blockValSet, BlockValSet timeValSet) { + ValueLongPair<Double> defaultValueLongPair = getDefaultValueTimePair(); + Double lastData = defaultValueLongPair.getValue(); + long lastTime = defaultValueLongPair.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 aggregateGroupResultWithRawDataSv(int length, int[] groupKeyArray, Review comment: The current code style won't reformat the explicit line breaks. 2 ways to reformat: 1. Uncheck the `Code Style` -> `Java` -> `Wrapping and Braces` -> `Keep when reformatting` -> `Line breaks` in the IDE preferences (this is my setting) 2. Manually remove the line breaks and then reformat -- 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]
