| 184 | } |
| 185 | |
| 186 | Status ExchangeNode::GetNext(RuntimeState* state, RowBatch* output_batch, bool* eos) { |
| 187 | SCOPED_TIMER(runtime_profile_->total_time_counter()); |
| 188 | ScopedGetNextEventAdder ea(this, eos); |
| 189 | RETURN_IF_ERROR(ExecDebugAction(TExecNodePhase::GETNEXT, state)); |
| 190 | if (ReachedLimit()) { |
| 191 | ReleaseRecvrResources(output_batch); |
| 192 | *eos = true; |
| 193 | return Status::OK(); |
| 194 | } else { |
| 195 | *eos = false; |
| 196 | } |
| 197 | |
| 198 | if (is_merging_) return GetNextMerging(state, output_batch, eos); |
| 199 | |
| 200 | while (true) { |
| 201 | { |
| 202 | SCOPED_TIMER(convert_row_batch_timer_); |
| 203 | RETURN_IF_CANCELLED(state); |
| 204 | RETURN_IF_ERROR(QueryMaintenance(state)); |
| 205 | if (input_batch_ != nullptr) { |
| 206 | // copy rows until we hit the limit/capacity or until we exhaust input_batch_ |
| 207 | int available_in_input = input_batch_->num_rows() - next_row_idx_; |
| 208 | int free_in_output = output_batch->capacity() - output_batch->num_rows(); |
| 209 | int rows_to_copy = std::min(available_in_input, free_in_output); |
| 210 | if (limit_ != -1) { |
| 211 | rows_to_copy = |
| 212 | static_cast<int>(std::min<int64_t>(rows_to_copy, limit_ - rows_returned())); |
| 213 | } |
| 214 | if (rows_to_copy > 0) { |
| 215 | int dst_offset = output_batch->AddRows(rows_to_copy); |
| 216 | output_batch->CopyRows(input_batch_, rows_to_copy, next_row_idx_, dst_offset); |
| 217 | next_row_idx_ += rows_to_copy; |
| 218 | output_batch->CommitRows(rows_to_copy); |
| 219 | IncrementNumRowsReturned(rows_to_copy); |
| 220 | COUNTER_SET(rows_returned_counter_, rows_returned()); |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | if (ReachedLimit()) { |
| 225 | ReleaseRecvrResources(output_batch); |
| 226 | *eos = true; |
| 227 | return Status::OK(); |
| 228 | } |
| 229 | if (output_batch->AtCapacity()) return Status::OK(); |
| 230 | } |
| 231 | |
| 232 | // we need more rows |
| 233 | stream_recvr_->TransferAllResources(output_batch); |
| 234 | RETURN_IF_ERROR(FillInputRowBatch(state)); |
| 235 | *eos = (input_batch_ == nullptr); |
| 236 | // No need to call CancelStream() on the receiver here as all incoming row batches |
| 237 | // have been consumed so we should have replied to all senders already. |
| 238 | if (*eos) return Status::OK(); |
| 239 | next_row_idx_ = 0; |
| 240 | DCHECK(input_batch_->row_desc()->LayoutIsPrefixOf(*output_batch->row_desc())); |
| 241 | } |
| 242 | } |
| 243 |
no test coverage detected