| 2549 | |
| 2550 | template <typename Type> |
| 2551 | Status ExecArrayChoose(KernelContext* ctx, const ExecSpan& batch, ExecResult* out) { |
| 2552 | ArraySpan* output = out->array_span_mutable(); |
| 2553 | const int64_t out_offset = output->offset; |
| 2554 | // Need a null bitmap if any input has nulls |
| 2555 | uint8_t* out_valid = nullptr; |
| 2556 | if (std::any_of(batch.values.begin(), batch.values.end(), |
| 2557 | [](const ExecValue& d) { return d.null_count() > 0; })) { |
| 2558 | out_valid = output->buffers[0].data; |
| 2559 | } else { |
| 2560 | bit_util::SetBitsTo(output->buffers[0].data, out_offset, batch.length, true); |
| 2561 | } |
| 2562 | uint8_t* out_values = output->buffers[1].data; |
| 2563 | int64_t row = 0; |
| 2564 | return VisitArrayValuesInline<Int64Type>( |
| 2565 | batch[0].array, |
| 2566 | [&](int64_t index) { |
| 2567 | if (index < 0 || (index + 1) >= batch.num_values()) { |
| 2568 | return Status::IndexError("choose: index ", index, " out of range"); |
| 2569 | } |
| 2570 | const auto& source = batch.values[index + 1]; |
| 2571 | CopyOneValue<Type>(source, row, out_valid, out_values, out_offset + row); |
| 2572 | row++; |
| 2573 | return Status::OK(); |
| 2574 | }, |
| 2575 | [&]() { |
| 2576 | // Index is null, but we should still initialize the output with some value |
| 2577 | const auto& source = batch.values[1]; |
| 2578 | CopyOneValue<Type>(source, row, out_valid, out_values, out_offset + row); |
| 2579 | bit_util::ClearBit(out_valid, out_offset + row); |
| 2580 | row++; |
| 2581 | return Status::OK(); |
| 2582 | }); |
| 2583 | } |
| 2584 | |
| 2585 | template <typename Type, typename Enable = void> |
| 2586 | struct ChooseFunctor { |
nothing calls this directly
no test coverage detected