| 475 | } |
| 476 | |
| 477 | void RowNumber::spillInput( |
| 478 | const RowVectorPtr& input, |
| 479 | memory::MemoryPool* pool) { |
| 480 | const auto numInput = input->size(); |
| 481 | |
| 482 | std::vector<uint32_t> spillPartitions(numInput); |
| 483 | const auto singlePartition = |
| 484 | spillHashFunction_->partition(*input, spillPartitions); |
| 485 | |
| 486 | const auto numPartitions = spillHashFunction_->numPartitions(); |
| 487 | |
| 488 | std::vector<BufferPtr> partitionIndices(numPartitions); |
| 489 | std::vector<vector_size_t*> rawPartitionIndices(numPartitions); |
| 490 | |
| 491 | for (auto i = 0; i < numPartitions; ++i) { |
| 492 | partitionIndices[i] = allocateIndices(numInput, pool); |
| 493 | rawPartitionIndices[i] = partitionIndices[i]->asMutable<vector_size_t>(); |
| 494 | } |
| 495 | |
| 496 | std::vector<vector_size_t> numSpillInputs(numPartitions, 0); |
| 497 | |
| 498 | for (auto row = 0; row < numInput; ++row) { |
| 499 | const auto partition = singlePartition.has_value() ? singlePartition.value() |
| 500 | : spillPartitions[row]; |
| 501 | rawPartitionIndices[partition][numSpillInputs[partition]++] = row; |
| 502 | } |
| 503 | |
| 504 | // Ensure vector are lazy loaded before spilling. |
| 505 | for (auto i = 0; i < input->childrenSize(); ++i) { |
| 506 | input->childAt(i)->loadedVector(); |
| 507 | } |
| 508 | |
| 509 | for (int32_t partition = 0; partition < numSpillInputs.size(); ++partition) { |
| 510 | const auto numInputs = numSpillInputs[partition]; |
| 511 | if (numInputs == 0) { |
| 512 | continue; |
| 513 | } |
| 514 | |
| 515 | inputSpiller_->spill( |
| 516 | partition, |
| 517 | wrapAndCombineDict(numInputs, partitionIndices[partition], input)); |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | } // namespace bytedance::bolt::exec |
nothing calls this directly
no test coverage detected