| 149 | } |
| 150 | |
| 151 | void 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 | |
| 194 | void SimpleAggregate::initLocalStateInternal(ResultSet* resultSet, ExecutionContext* context) { |
| 195 | BaseAggregate::initLocalStateInternal(resultSet, context); |
no test coverage detected