| 596 | } |
| 597 | |
| 598 | void SortBuffer::getOutputWithSpill() { |
| 599 | BOLT_DCHECK_EQ(sortedRows_.size(), 0); |
| 600 | if (spillMerger_) { |
| 601 | BOLT_CHECK_NOT_NULL(spillMerger_); |
| 602 | |
| 603 | int32_t outputRow = 0; |
| 604 | int32_t outputSize = 0; |
| 605 | bool isEndOfBatch = false; |
| 606 | while (outputRow + outputSize < output_->size()) { |
| 607 | SpillMergeStream* stream = spillMerger_->next(); |
| 608 | BOLT_CHECK_NOT_NULL(stream); |
| 609 | |
| 610 | spillSources_[outputSize] = &stream->current(); |
| 611 | spillSourceRows_[outputSize] = stream->currentIndex(&isEndOfBatch); |
| 612 | ++outputSize; |
| 613 | if (FOLLY_UNLIKELY(isEndOfBatch)) { |
| 614 | // The stream is at end of input batch. Need to copy out the rows before |
| 615 | // fetching next batch in 'pop'. |
| 616 | gatherCopy( |
| 617 | output_.get(), |
| 618 | outputRow, |
| 619 | outputSize, |
| 620 | spillSources_, |
| 621 | spillSourceRows_, |
| 622 | columnMap_); |
| 623 | outputRow += outputSize; |
| 624 | outputSize = 0; |
| 625 | } |
| 626 | // Advance the stream. |
| 627 | stream->pop(); |
| 628 | } |
| 629 | BOLT_CHECK_EQ(outputRow + outputSize, output_->size()); |
| 630 | |
| 631 | if (FOLLY_LIKELY(outputSize != 0)) { |
| 632 | gatherCopy( |
| 633 | output_.get(), |
| 634 | outputRow, |
| 635 | outputSize, |
| 636 | spillSources_, |
| 637 | spillSourceRows_, |
| 638 | columnMap_); |
| 639 | } |
| 640 | |
| 641 | numOutputRows_ += output_->size(); |
| 642 | } else { |
| 643 | BOLT_CHECK_NOT_NULL(rowBasedSpillMerger_); |
| 644 | |
| 645 | int32_t outputRow = 0; |
| 646 | bool isEndOfBatch = false; |
| 647 | std::vector<char*> rows; |
| 648 | while (outputRow + rows.size() < output_->size()) { |
| 649 | RowBasedSpillMergeStream* stream = rowBasedSpillMerger_->next(); |
| 650 | BOLT_CHECK_NOT_NULL(stream); |
| 651 | |
| 652 | const auto& currentBatch = stream->current(); |
| 653 | auto index = stream->currentIndex(&isEndOfBatch); |
| 654 | rows.push_back(currentBatch[index]); |
| 655 | if (FOLLY_UNLIKELY(isEndOfBatch)) { |
nothing calls this directly
no test coverage detected