weixiangsun commented on a change in pull request #8029: URL: https://github.com/apache/pinot/pull/8029#discussion_r815391461
########## File path: pinot-core/src/main/java/org/apache/pinot/core/query/reduce/PreAggregationGapFillDataTableReducer.java ########## @@ -0,0 +1,775 @@ +/** + * 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.reduce; + +import com.google.common.base.Preconditions; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.PriorityQueue; +import java.util.Set; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import org.apache.pinot.common.exception.QueryException; +import org.apache.pinot.common.metrics.BrokerMetrics; +import org.apache.pinot.common.request.context.ExpressionContext; +import org.apache.pinot.common.request.context.FunctionContext; +import org.apache.pinot.common.response.broker.BrokerResponseNative; +import org.apache.pinot.common.response.broker.QueryProcessingException; +import org.apache.pinot.common.response.broker.ResultTable; +import org.apache.pinot.common.utils.DataSchema; +import org.apache.pinot.common.utils.DataSchema.ColumnDataType; +import org.apache.pinot.common.utils.DataTable; +import org.apache.pinot.core.common.BlockValSet; +import org.apache.pinot.core.data.table.ConcurrentIndexedTable; +import org.apache.pinot.core.data.table.IndexedTable; +import org.apache.pinot.core.data.table.Key; +import org.apache.pinot.core.data.table.Record; +import org.apache.pinot.core.data.table.SimpleIndexedTable; +import org.apache.pinot.core.data.table.UnboundedConcurrentIndexedTable; +import org.apache.pinot.core.operator.combine.GroupByOrderByCombineOperator; +import org.apache.pinot.core.query.aggregation.function.AggregationFunction; +import org.apache.pinot.core.query.aggregation.function.AggregationFunctionFactory; +import org.apache.pinot.core.query.aggregation.groupby.GroupByResultHolder; +import org.apache.pinot.core.query.request.context.QueryContext; +import org.apache.pinot.core.query.selection.SelectionOperatorUtils; +import org.apache.pinot.core.transport.ServerRoutingInstance; +import org.apache.pinot.core.util.GapfillUtils; +import org.apache.pinot.core.util.GroupByUtils; +import org.apache.pinot.core.util.trace.TraceRunnable; +import org.apache.pinot.spi.data.DateTimeFormatSpec; +import org.apache.pinot.spi.data.DateTimeGranularitySpec; + +/** + * Helper class to reduce and set Aggregation results into the BrokerResponseNative + */ +@SuppressWarnings({"rawtypes", "unchecked"}) +public class PreAggregationGapFillDataTableReducer implements DataTableReducer { + private static final int MIN_DATA_TABLES_FOR_CONCURRENT_REDUCE = 2; // TBD, find a better value. + + private final QueryContext _queryContext; + + private final int _limitForAggregatedResult; + private int _limitForGapfilledResult; + + private final DateTimeGranularitySpec _dateTimeGranularity; + private final DateTimeFormatSpec _dateTimeFormatter; + private final long _startMs; + private final long _endMs; + private final long _timeBucketSize; + + private final List<Integer> _groupByKeyIndexes; + private boolean [] _isGroupBySelections; + private final Set<Key> _groupByKeys; + private final Map<Key, Object[]> _previousByGroupKey; + private final Map<String, ExpressionContext> _fillExpressions; + private final List<ExpressionContext> _timeSeries; + private final GapfillUtils.GapfillType _gapfillType; + + PreAggregationGapFillDataTableReducer(QueryContext queryContext) { + _queryContext = queryContext; + _gapfillType = queryContext.getGapfillType(); + _limitForAggregatedResult = queryContext.getLimit(); + if (_gapfillType == GapfillUtils.GapfillType.AGGREGATE_GAP_FILL + || _gapfillType == GapfillUtils.GapfillType.GAP_FILL) { + _limitForGapfilledResult = queryContext.getLimit(); + } else { + _limitForGapfilledResult = queryContext.getSubQueryContext().getLimit(); + } + + ExpressionContext gapFillSelection = GapfillUtils.getGapfillExpressionContext(queryContext); + + Preconditions.checkArgument( + gapFillSelection != null && gapFillSelection.getFunction() != null, "Gapfill Expression should be function."); + List<ExpressionContext> args = gapFillSelection.getFunction().getArguments(); + Preconditions.checkArgument( + args.size() > 5, "PreAggregateGapFill does not have correct number of arguments."); + Preconditions.checkArgument( + args.get(1).getLiteral() != null, "The second argument of PostAggregateGapFill should be TimeFormatter."); + Preconditions.checkArgument( + args.get(2).getLiteral() != null, "The third argument of PostAggregateGapFill should be start time."); + Preconditions.checkArgument( + args.get(3).getLiteral() != null, "The fourth argument of PostAggregateGapFill should be end time."); + Preconditions.checkArgument( + args.get(4).getLiteral() != null, "The fifth argument of PostAggregateGapFill should be time bucket size."); Review comment: Fixed -- 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]
