lidavidm commented on code in PR #15291:
URL: https://github.com/apache/arrow/pull/15291#discussion_r1068102089
##########
cpp/src/arrow/compute/kernels/scalar_if_else.cc:
##########
@@ -723,12 +734,24 @@ struct IfElseFunctor<Type, enable_if_base_binary<Type>> {
// ASA
static Status Call(KernelContext* ctx, const ArraySpan& cond, const Scalar&
left,
const ArraySpan& right, ExecResult* out) {
- std::string_view left_data = internal::UnboxScalar<Type>::Unbox(left);
- auto left_size = static_cast<OffsetType>(left_data.size());
-
const auto* right_offsets = right.GetValues<OffsetType>(1);
const uint8_t* right_data = right.buffers[2].data;
+ if (!left.is_valid) { // left is null scalar, only need to copy right
data to output
+ auto& out_data = *out->array_data();
Review Comment:
nit: we mostly use pointers instead of non-const references
##########
cpp/src/arrow/compute/kernels/scalar_if_else.cc:
##########
@@ -723,12 +734,24 @@ struct IfElseFunctor<Type, enable_if_base_binary<Type>> {
// ASA
static Status Call(KernelContext* ctx, const ArraySpan& cond, const Scalar&
left,
const ArraySpan& right, ExecResult* out) {
- std::string_view left_data = internal::UnboxScalar<Type>::Unbox(left);
- auto left_size = static_cast<OffsetType>(left_data.size());
-
const auto* right_offsets = right.GetValues<OffsetType>(1);
const uint8_t* right_data = right.buffers[2].data;
+ if (!left.is_valid) { // left is null scalar, only need to copy right
data to output
+ auto& out_data = *out->array_data();
+ auto offset_length = (cond.length + 1) * sizeof(OffsetType);
+ ARROW_ASSIGN_OR_RAISE(out_data.buffers[1], ctx->Allocate(offset_length));
+ memcpy(out_data.buffers[1]->mutable_data(), right_offsets,
offset_length);
Review Comment:
nit: stick with std::memcpy for consistency?
--
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]