| 650 | } |
| 651 | |
| 652 | std::unique_ptr<Spiller::SpillStatus> Spiller::writeSpill(int32_t partition) { |
| 653 | BOLT_CHECK(type_ != Type::kHashJoinProbe && type_ != Type::kLocalMergeInput); |
| 654 | |
| 655 | // 1. The flush threshold is controlled by writeBufferSize_ from configuration |
| 656 | // 2. The materialized size is controlled by kMaxReadBufferSize |
| 657 | constexpr int32_t kTargetBatchBytes = (1UL << 20) - |
| 658 | AlignedBuffer::kPaddedSize; // 1M, Same as kMaxReadBufferSize |
| 659 | constexpr int32_t kTargetBatchRows = 4096; |
| 660 | |
| 661 | RowVectorPtr spillVector; |
| 662 | auto& run = spillRuns_[partition]; |
| 663 | try { |
| 664 | ensureSorted(run); |
| 665 | int64_t totalBytes = 0; |
| 666 | size_t written = 0; |
| 667 | if (spillMode_ == Mode::kRowVector) { |
| 668 | while (written < run.rows.size()) { |
| 669 | if (hybridSortEnabled_) { |
| 670 | extractSpillVectorHybrid( |
| 671 | run.rows, |
| 672 | kTargetBatchRows, |
| 673 | kTargetBatchBytes, |
| 674 | spillVector, |
| 675 | written); |
| 676 | } else { |
| 677 | extractSpillVector( |
| 678 | run.rows, |
| 679 | kTargetBatchRows, |
| 680 | kTargetBatchBytes, |
| 681 | spillVector, |
| 682 | written); |
| 683 | } |
| 684 | totalBytes += state_.appendToPartition(partition, spillVector); |
| 685 | spillVector->prepareForReuse(); |
| 686 | if (totalBytes > state_.targetFileSize()) { |
| 687 | BOLT_CHECK(!needSort()); |
| 688 | state_.finishFile(partition); |
| 689 | // reset to 0 after close file |
| 690 | totalBytes = 0; |
| 691 | } |
| 692 | } |
| 693 | } else { |
| 694 | if (spillConfig_->needSetNextEqual) { |
| 695 | spillConfig_->aggBypassHTEqualNum += setNextEqualForAgg(run); |
| 696 | } |
| 697 | written = run.rows.size(); |
| 698 | state_.appendToPartition(partition, run.rows, rowType_, rowInfo_.value()); |
| 699 | } |
| 700 | return std::make_unique<SpillStatus>(partition, written, nullptr); |
| 701 | } catch (const std::exception& e) { |
| 702 | // The exception is passed to the caller thread which checks this in |
| 703 | // advanceSpill(). |
| 704 | return std::make_unique<SpillStatus>( |
| 705 | partition, 0, std::current_exception()); |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | void Spiller::runSpill(bool lastRun) { |
nothing calls this directly
no test coverage detected