| 98 | |
| 99 | template <bool needSort> |
| 100 | void SpillableWindowBuild<needSort>::spill() { |
| 101 | if (inputRows_.size() == 0) { |
| 102 | return; |
| 103 | } |
| 104 | if (spillers_.size() < currentSpilledPartition_ + 1) { |
| 105 | setupSpiller(); |
| 106 | } |
| 107 | |
| 108 | bool keepLastRow = |
| 109 | (inputRows_[inputRows_.size() - 1] == previousRow_ && !lastRun_); |
| 110 | if (!sortSpiller_) { |
| 111 | RowVectorPtr lastRowPtr = nullptr; |
| 112 | if (keepLastRow) { |
| 113 | if (inputRows_.size() == 1) { |
| 114 | return; |
| 115 | } |
| 116 | |
| 117 | lastRowPtr = BaseVector::create<RowVector>( |
| 118 | inputType_, 1, memory::spillMemoryPool()); |
| 119 | for (auto i = 0; i < inputType_->size(); ++i) { |
| 120 | data_->extractColumn( |
| 121 | &previousRow_, 1, data_->columnAt(i), 0, lastRowPtr->childAt(i)); |
| 122 | } |
| 123 | |
| 124 | // pop_back() here only for aggregate window function |
| 125 | // for non-aggregate window function (lag, lead), need to keep the |
| 126 | // previousRow in inputRows_ when create partialPartiton |
| 127 | // after creating partialPartiton, pop_back() from inputRows_ |
| 128 | if (isAggWindowFunc()) { |
| 129 | inputRows_.pop_back(); |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | // calculate results before spilling |
| 134 | auto currentPartition = createPartialPartition(); |
| 135 | if (keepLastRow && !isAggWindowFunc()) { |
| 136 | inputRows_.pop_back(); |
| 137 | } |
| 138 | for (auto i = 0; i < windowFunctions_.size(); ++i) { |
| 139 | windowFunctions_[i]->resetPartition(currentPartition.get()); |
| 140 | windowFunctions_[i]->computeSpillableAggregate(doInitialize_); |
| 141 | } |
| 142 | doInitialize_ = false; |
| 143 | |
| 144 | spillers_[currentSpilledPartition_]->spill(inputRows_, lastRun_); |
| 145 | |
| 146 | spilledNumRows_ += inputRows_.size(); |
| 147 | |
| 148 | if (inputRows_.size() == data_->numRows()) { |
| 149 | data_->clear(); |
| 150 | data_->pool()->release(); |
| 151 | } else { |
| 152 | data_->eraseRows( |
| 153 | folly::Range<char**>(inputRows_.data(), inputRows_.size())); |
| 154 | } |
| 155 | inputRows_.clear(); |
| 156 | |
| 157 | if (keepLastRow) { |
nothing calls this directly
no test coverage detected