| 404 | } |
| 405 | |
| 406 | bool ExecSpanIterator::Next(ExecSpan* span) { |
| 407 | if (!initialized_) { |
| 408 | span->length = 0; |
| 409 | |
| 410 | // The first time this is called, we populate the output span with any |
| 411 | // Scalar or Array arguments in the ExecValue struct, and then just |
| 412 | // increment array offsets below. If any arguments are ChunkedArray, then |
| 413 | // the internal ArraySpans will see their members updated during the |
| 414 | // iteration |
| 415 | span->values.resize(args_->size()); |
| 416 | for (size_t i = 0; i < args_->size(); ++i) { |
| 417 | const Datum& arg = (*args_)[i]; |
| 418 | if (arg.is_scalar()) { |
| 419 | span->values[i].SetScalar(arg.scalar().get()); |
| 420 | } else if (arg.is_array()) { |
| 421 | const ArrayData& arr = *arg.array(); |
| 422 | span->values[i].SetArray(arr); |
| 423 | value_offsets_[i] = arr.offset; |
| 424 | } else { |
| 425 | // Populate members from the first chunk |
| 426 | const ChunkedArray& carr = *arg.chunked_array(); |
| 427 | if (carr.num_chunks() > 0) { |
| 428 | const ArrayData& arr = *carr.chunk(0)->data(); |
| 429 | span->values[i].SetArray(arr); |
| 430 | value_offsets_[i] = arr.offset; |
| 431 | } else { |
| 432 | // Fill as zero-length array |
| 433 | ::arrow::internal::FillZeroLengthArray(carr.type().get(), |
| 434 | &span->values[i].array); |
| 435 | span->values[i].scalar = nullptr; |
| 436 | } |
| 437 | have_chunked_arrays_ = true; |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | if (have_all_scalars_ && promote_if_all_scalars_) { |
| 442 | PromoteExecSpanScalars(span); |
| 443 | } |
| 444 | |
| 445 | initialized_ = true; |
| 446 | } else if (position_ == length_) { |
| 447 | // We've emitted at least one span and we're at the end so we are done |
| 448 | return false; |
| 449 | } |
| 450 | |
| 451 | // Determine how large the common contiguous "slice" of all the arguments is |
| 452 | int64_t iteration_size = std::min(length_ - position_, max_chunksize_); |
| 453 | if (have_chunked_arrays_) { |
| 454 | iteration_size = GetNextChunkSpan(iteration_size, span); |
| 455 | } |
| 456 | |
| 457 | // Now, adjust the span |
| 458 | span->length = iteration_size; |
| 459 | for (size_t i = 0; i < args_->size(); ++i) { |
| 460 | const Datum& arg = args_->at(i); |
| 461 | if (!arg.is_scalar()) { |
| 462 | ArraySpan* arr = &span->values[i].array; |
| 463 | arr->SetSlice(value_positions_[i] + value_offsets_[i], iteration_size); |