pitrou commented on a change in pull request #10642:
URL: https://github.com/apache/arrow/pull/10642#discussion_r682798937
##########
File path: cpp/src/arrow/compute/kernels/scalar_if_else.cc
##########
@@ -1606,6 +1620,203 @@ struct CoalesceFunctor<Type,
enable_if_base_binary<Type>> {
}
};
+template <typename Type>
+Status ExecScalarChoose(KernelContext* ctx, const ExecBatch& batch, Datum*
out) {
+ const auto& index_scalar = *batch[0].scalar();
+ if (!index_scalar.is_valid) {
+ if (out->is_array()) {
+ auto source = MakeNullScalar(out->type());
+ ArrayData* output = out->mutable_array();
+ CopyValues<Type>(source, /*row=*/0, batch.length,
+ output->GetMutableValues<uint8_t>(0,
/*absolute_offset=*/0),
+ output->GetMutableValues<uint8_t>(1,
/*absolute_offset=*/0),
+ output->offset);
+ }
+ return Status::OK();
+ }
+ auto index = UnboxScalar<Int64Type>::Unbox(index_scalar);
+ if (index < 0 || static_cast<size_t>(index + 1) >= batch.values.size()) {
+ return Status::IndexError("choose: index ", index, " out of range");
+ }
+ auto source = batch.values[index + 1];
+ if (out->is_scalar()) {
+ *out = source;
+ } else {
+ ArrayData* output = out->mutable_array();
+ CopyValues<Type>(source, /*row=*/0, batch.length,
+ output->GetMutableValues<uint8_t>(0,
/*absolute_offset=*/0),
+ output->GetMutableValues<uint8_t>(1,
/*absolute_offset=*/0),
+ output->offset);
+ }
+ return Status::OK();
+}
+
+template <typename Type>
+Status ExecArrayChoose(KernelContext* ctx, const ExecBatch& batch, Datum* out)
{
+ ArrayData* output = out->mutable_array();
+ const int64_t out_offset = output->offset;
+ // Need a null bitmap if any input has nulls
+ uint8_t* out_valid = nullptr;
+ if (std::any_of(batch.values.begin(), batch.values.end(),
+ [](const Datum& d) { return d.null_count() > 0; })) {
+ out_valid = output->buffers[0]->mutable_data();
+ } else {
+ BitUtil::SetBitsTo(output->buffers[0]->mutable_data(), out_offset,
batch.length,
+ true);
Review comment:
I see, thanks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]