| 302 | } |
| 303 | |
| 304 | Status UnionNode::GetNext(RuntimeState* state, RowBatch* row_batch, bool* eos) { |
| 305 | SCOPED_TIMER(runtime_profile_->total_time_counter()); |
| 306 | ScopedGetNextEventAdder ea(this, eos); |
| 307 | RETURN_IF_ERROR(ExecDebugAction(TExecNodePhase::GETNEXT, state)); |
| 308 | RETURN_IF_CANCELLED(state); |
| 309 | RETURN_IF_ERROR(QueryMaintenance(state)); |
| 310 | |
| 311 | if (to_close_child_idx_ != -1) { |
| 312 | // The previous child needs to be closed if passthrough was enabled for it. In the non |
| 313 | // passthrough case, the child was already closed in the previous call to GetNext(). |
| 314 | DCHECK(IsChildPassthrough(to_close_child_idx_)); |
| 315 | DCHECK(!IsInSubplan()); |
| 316 | child(to_close_child_idx_)->Close(state); |
| 317 | to_close_child_idx_ = -1; |
| 318 | } |
| 319 | |
| 320 | // Save the number of rows in case GetNext() is called with a non-empty batch, which can |
| 321 | // happen in a subplan. |
| 322 | int num_rows_before = row_batch->num_rows(); |
| 323 | |
| 324 | if (HasMorePassthrough()) { |
| 325 | RETURN_IF_ERROR(GetNextPassThrough(state, row_batch)); |
| 326 | } else if (HasMoreMaterialized()) { |
| 327 | RETURN_IF_ERROR(GetNextMaterialized(state, row_batch)); |
| 328 | } else if (HasMoreConst(state)) { |
| 329 | RETURN_IF_ERROR(GetNextConst(state, row_batch)); |
| 330 | } |
| 331 | |
| 332 | int num_rows_added = row_batch->num_rows() - num_rows_before; |
| 333 | DCHECK_GE(num_rows_added, 0); |
| 334 | if (limit_ != -1 && rows_returned() + num_rows_added > limit_) { |
| 335 | // Truncate the row batch if we went over the limit. |
| 336 | num_rows_added = limit_ - rows_returned(); |
| 337 | row_batch->set_num_rows(num_rows_before + num_rows_added); |
| 338 | DCHECK_GE(num_rows_added, 0); |
| 339 | } |
| 340 | IncrementNumRowsReturned(num_rows_added); |
| 341 | |
| 342 | *eos = ReachedLimit() || |
| 343 | (!HasMorePassthrough() && !HasMoreMaterialized() && !HasMoreConst(state)); |
| 344 | |
| 345 | COUNTER_SET(rows_returned_counter_, rows_returned()); |
| 346 | return Status::OK(); |
| 347 | } |
| 348 | |
| 349 | Status UnionNode::Reset(RuntimeState* state, RowBatch* row_batch) { |
| 350 | child_idx_ = 0; |
no test coverage detected