MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / finalizePartitions

Method finalizePartitions

src/processor/operator/aggregate/simple_aggregate.cpp:151–192  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

149}
150
151void SimpleAggregateSharedState::finalizePartitions(storage::MemoryManager* memoryManager,
152 const std::vector<AggregateInfo>& aggInfos) {
153 if (!hasDistinct) {
154 return;
155 }
156 InMemOverflowBuffer localOverflowBuffer(memoryManager);
157 BaseAggregateSharedState::finalizePartitions(globalPartitions, [&](auto& partition) {
158 for (size_t i = 0; i < partition.distinctTables.size(); i++) {
159 if (!aggregateFunctions[i].isDistinct) {
160 continue;
161 }
162 auto& [hashTable, queue, state] = partition.distinctTables[i];
163 if (queue) {
164 DASSERT(hashTable);
165 queue->mergeInto(*hashTable);
166 }
167
168 ValueVector aggregateVector(aggInfos[i].distinctAggKeyType.copy(), memoryManager,
169 std::make_shared<DataChunkState>());
170 const auto& ft = hashTable->getFactorizedTable();
171 ft_tuple_idx_t startTupleIdx = 0;
172 ft_tuple_idx_t numTuplesToScan =
173 std::min(DEFAULT_VECTOR_CAPACITY, ft->getNumTuples() - startTupleIdx);
174 std::array<uint32_t, 1> colIdxToScan = {0};
175 std::array<ValueVector*, 1> vectors = {&aggregateVector};
176 while (numTuplesToScan > 0) {
177 ft->scan(vectors, startTupleIdx, numTuplesToScan, colIdxToScan);
178 aggregateFunctions[i].updateAllState((uint8_t*)state.get(), &aggregateVector,
179 1 /*multiplicity*/, &localOverflowBuffer);
180 startTupleIdx += numTuplesToScan;
181 numTuplesToScan =
182 std::min(DEFAULT_VECTOR_CAPACITY, ft->getNumTuples() - startTupleIdx);
183 }
184 hashTable.reset();
185 queue.reset();
186 }
187 });
188 {
189 std::unique_lock lck{mtx};
190 aggregateOverflowBuffer.merge(localOverflowBuffer);
191 }
192}
193
194void SimpleAggregate::initLocalStateInternal(ResultSet* resultSet, ExecutionContext* context) {
195 BaseAggregate::initLocalStateInternal(resultSet, context);

Callers 1

executeInternalMethod · 0.45

Calls 10

mergeIntoMethod · 0.80
getFactorizedTableMethod · 0.80
updateAllStateMethod · 0.80
sizeMethod · 0.45
copyMethod · 0.45
getNumTuplesMethod · 0.45
scanMethod · 0.45
getMethod · 0.45
resetMethod · 0.45
mergeMethod · 0.45

Tested by

no test coverage detected