MCPcopy Create free account
hub / github.com/apache/arrow / ExecArrayChoose

Function ExecArrayChoose

cpp/src/arrow/compute/kernels/scalar_if_else.cc:2551–2583  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2549
2550template <typename Type>
2551Status 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
2585template <typename Type, typename Enable = void>
2586struct ChooseFunctor {

Callers

nothing calls this directly

Calls 8

IndexErrorFunction · 0.85
ClearBitFunction · 0.85
SetBitsToFunction · 0.50
OKFunction · 0.50
beginMethod · 0.45
endMethod · 0.45
null_countMethod · 0.45
num_valuesMethod · 0.45

Tested by

no test coverage detected