| 2175 | |
| 2176 | const auto rowSizeFromContainer = table_->rows()->estimateRowSize(); |
| 2177 | if (!hasExternalMemoryAccumulators_) { |
| 2178 | return rowSizeFromContainer; |
| 2179 | } |
| 2180 | |
| 2181 | // RowContainer::estimateRowSize() only accounts for RowContainer's row blocks |
| 2182 | // and HashStringAllocator (e.g. strings). For aggregates which allocate state |
| 2183 | // directly from MemoryPool (external memory), incorporate pool usage per |
| 2184 | // group to avoid under-estimation and too large output batches. |
| 2185 | const int64_t rowSizeFromPool = std::max<int64_t>( |
| 2186 | 1, static_cast<int64_t>(pool_.currentBytes() / table_->numDistinct())); |
| 2187 | const int64_t rowSize = |
| 2188 | std::max<int64_t>(rowSizeFromPool, rowSizeFromContainer.value_or(0)); |
| 2189 | return rowSize; |
| 2190 | } |
| 2191 | |
| 2192 | void GroupingSet::convertCompositeInput( |
| 2193 | const std::vector<AggregateInfo>& extractAggregates, |
| 2194 | const CompositeRowVectorPtr& input, |
| 2195 | const RowVectorPtr& result) { |
| 2196 | if (!table_) { |
| 2197 | createHashTable(); |
| 2198 | } |
| 2199 | auto* container = table_->rows(); |
| 2200 | // initialize extractAggregates to make sure Aggregate::numNulls_ not 0 if it |
| 2201 | // is used |
| 2202 | if (!extractAggregatesInitialized_) { |
| 2203 | // fixedRowSize should be accuracy |
| 2204 | auto rowSize = container->fixedRowSize() + 16; |
| 2205 | char* rowPtr = static_cast<char*>(pool_.allocate(rowSize)); |
| 2206 | const std::vector<char*> tmpGroups{rowPtr}; |
| 2207 | const std::vector<vector_size_t> groupIndex{0}; |
| 2208 | initializeAggregates(extractAggregates, *container, false); |
| 2209 | for (auto i = 0; i < extractAggregates.size(); ++i) { |
| 2210 | extractAggregates[i].function->initializeNewGroups( |
| 2211 | const_cast<char**>(tmpGroups.data()), groupIndex); |
| 2212 | } |
| 2213 | pool_.free(rowPtr, rowSize); |
| 2214 | extractAggregatesInitialized_ = true; |
| 2215 | } |
| 2216 | auto& inputRows = input->rawRows(); |
| 2217 | for (auto& row : inputRows) { |
| 2218 | ContainerRow2RowSerde::deserialize( |
| 2219 | const_cast<char*&>(row), rowInfo_.value(), false); |
| 2220 | } |
| 2221 | |
| 2222 | for (auto i = 0; i < keyChannels_.size(); ++i) { |
| 2223 | rowToColumnVector( |
no test coverage detected