Beyyes commented on code in PR #13651: URL: https://github.com/apache/iotdb/pull/13651#discussion_r1779857682
########## iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/aggregation/AggregationOperator.java: ########## @@ -0,0 +1,158 @@ +/* + * 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.iotdb.db.queryengine.execution.operator.source.relational.aggregation; + +import org.apache.iotdb.db.queryengine.execution.MemoryEstimationHelper; +import org.apache.iotdb.db.queryengine.execution.operator.Operator; +import org.apache.iotdb.db.queryengine.execution.operator.OperatorContext; +import org.apache.iotdb.db.queryengine.execution.operator.process.ProcessOperator; +import org.apache.iotdb.db.queryengine.execution.operator.source.relational.TableScanOperator; +import org.apache.iotdb.db.queryengine.plan.planner.memory.MemoryReservationManager; + +import com.google.common.util.concurrent.ListenableFuture; +import org.apache.tsfile.block.column.Column; +import org.apache.tsfile.block.column.ColumnBuilder; +import org.apache.tsfile.common.conf.TSFileDescriptor; +import org.apache.tsfile.read.common.block.TsBlock; +import org.apache.tsfile.read.common.block.TsBlockBuilder; +import org.apache.tsfile.read.common.block.column.RunLengthEncodedColumn; +import org.apache.tsfile.utils.RamUsageEstimator; + +import java.util.List; + +import static com.google.common.collect.ImmutableList.toImmutableList; + +public class AggregationOperator implements ProcessOperator { + private static final long INSTANCE_SIZE = + RamUsageEstimator.shallowSizeOfInstance(AggregationOperator.class); + + private final OperatorContext operatorContext; + + private final Operator child; + + private final List<Aggregator> aggregators; + + private final TsBlockBuilder resultBuilder; + + private final ColumnBuilder[] resultColumnsBuilder; + + private final long maxReturnSize = + TSFileDescriptor.getInstance().getConfig().getMaxTsBlockSizeInBytes(); + + protected MemoryReservationManager memoryReservationManager; + + private boolean finished = false; + + public AggregationOperator( + OperatorContext operatorContext, Operator child, List<Aggregator> aggregators) { + this.operatorContext = operatorContext; + this.child = child; + this.aggregators = aggregators; + this.resultBuilder = + new TsBlockBuilder( + aggregators.stream().map(Aggregator::getType).collect(toImmutableList())); + this.resultColumnsBuilder = resultBuilder.getValueColumnBuilders(); + this.memoryReservationManager = + operatorContext + .getDriverContext() + .getFragmentInstanceContext() + .getMemoryReservationContext(); + } + + @Override + public ListenableFuture<?> isBlocked() { + return child.isBlocked(); + } + + @Override + public boolean hasNext() throws Exception { + return !finished; + } + + @Override + public TsBlock next() throws Exception { + // Each call only calculate at most once, no need to check time slice. + TsBlock block; + if (child.hasNextWithTimer()) { Review Comment: Add is resultTsBlock.isFull() judgement -- 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: reviews-unsubscr...@iotdb.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org