| 114 | } |
| 115 | |
| 116 | Status PartialSortNode::GetNext(RuntimeState* state, RowBatch* row_batch, bool* eos) { |
| 117 | SCOPED_TIMER(runtime_profile_->total_time_counter()); |
| 118 | ScopedGetNextEventAdder ea(this, eos); |
| 119 | RETURN_IF_ERROR(ExecDebugAction(TExecNodePhase::GETNEXT, state)); |
| 120 | RETURN_IF_CANCELLED(state); |
| 121 | RETURN_IF_ERROR(QueryMaintenance(state)); |
| 122 | |
| 123 | DCHECK_EQ(row_batch->num_rows(), 0); |
| 124 | if (!sorter_eos_) { |
| 125 | // There were rows in the current run that didn't fit in the last output batch. |
| 126 | RETURN_IF_ERROR(sorter_->GetNext(row_batch, &sorter_eos_)); |
| 127 | if (sorter_eos_) { |
| 128 | sorter_->Reset(); |
| 129 | *eos = input_eos_; |
| 130 | } |
| 131 | IncrementNumRowsReturned(row_batch->num_rows()); |
| 132 | COUNTER_SET(rows_returned_counter_, rows_returned()); |
| 133 | return Status::OK(); |
| 134 | } |
| 135 | |
| 136 | if (input_eos_) { |
| 137 | *eos = true; |
| 138 | return Status::OK(); |
| 139 | } |
| 140 | |
| 141 | DCHECK(sorter_eos_); |
| 142 | RETURN_IF_ERROR(sorter_->Open()); |
| 143 | do { |
| 144 | if (input_batch_index_ == input_batch_->num_rows()) { |
| 145 | input_batch_->Reset(); |
| 146 | input_batch_index_ = 0; |
| 147 | MonotonicStopWatch timer; |
| 148 | timer.Start(); |
| 149 | Status status = child(0)->GetNext(state, input_batch_.get(), &input_eos_); |
| 150 | timer.Stop(); |
| 151 | RETURN_IF_ERROR(status); |
| 152 | child_get_next_timer_->UpdateCounter(timer.ElapsedTime()); |
| 153 | } |
| 154 | |
| 155 | int num_processed; |
| 156 | RETURN_IF_ERROR( |
| 157 | sorter_->AddBatchNoSpill(input_batch_.get(), input_batch_index_, &num_processed)); |
| 158 | input_batch_index_ += num_processed; |
| 159 | DCHECK(input_batch_index_ <= input_batch_->num_rows()); |
| 160 | RETURN_IF_ERROR(QueryMaintenance(state)); |
| 161 | } while (input_batch_index_ == input_batch_->num_rows() && !input_eos_); |
| 162 | |
| 163 | RETURN_IF_ERROR(sorter_->InputDone()); |
| 164 | RETURN_IF_ERROR(sorter_->GetNext(row_batch, &sorter_eos_)); |
| 165 | if (sorter_eos_) { |
| 166 | sorter_->Reset(); |
| 167 | *eos = input_eos_; |
| 168 | } |
| 169 | |
| 170 | IncrementNumRowsReturned(row_batch->num_rows()); |
| 171 | COUNTER_SET(rows_returned_counter_, rows_returned()); |
| 172 | return Status::OK(); |
| 173 | } |
nothing calls this directly
no test coverage detected