Skip to content

Commit 9f2edbc

Browse files
author
Ebraam
committed
GH-49410: [C++] Fix if_else null-scalar fast paths for sliced BaseBinary arrays
1 parent 95b8bf8 commit 9f2edbc

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

cpp/src/arrow/compute/kernels/scalar_if_else.cc

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -745,9 +745,17 @@ struct IfElseFunctor<Type, enable_if_base_binary<Type>> {
745745
ARROW_ASSIGN_OR_RAISE(out_data->buffers[1], ctx->Allocate(offset_length));
746746
std::memcpy(out_data->buffers[1]->mutable_data(), right_offsets, offset_length);
747747

748-
auto right_data_length = right_offsets[right.length] - right_offsets[0];
748+
OffsetType base = right_offsets[0];
749+
auto* out_offsets = reinterpret_cast<OffsetType*>(
750+
out_data->buffers[1]->mutable_data());
751+
for (int64_t i = 0; i <= cond.length; ++i) {
752+
out_offsets[i] = right_offsets[i] - base;
753+
}
754+
755+
auto right_data_length = right_offsets[right.length] - base;
749756
ARROW_ASSIGN_OR_RAISE(out_data->buffers[2], ctx->Allocate(right_data_length));
750-
std::memcpy(out_data->buffers[2]->mutable_data(), right_data, right_data_length);
757+
std::memcpy(out_data->buffers[2]->mutable_data(), right_data + base,
758+
right_data_length);
751759
return Status::OK();
752760
}
753761

@@ -785,9 +793,17 @@ struct IfElseFunctor<Type, enable_if_base_binary<Type>> {
785793
ARROW_ASSIGN_OR_RAISE(out_data->buffers[1], ctx->Allocate(offset_length));
786794
std::memcpy(out_data->buffers[1]->mutable_data(), left_offsets, offset_length);
787795

788-
auto left_data_length = left_offsets[left.length] - left_offsets[0];
796+
OffsetType base = left_offsets[0];
797+
auto* out_offsets = reinterpret_cast<OffsetType*>(
798+
out_data->buffers[1]->mutable_data());
799+
for (int64_t i = 0; i <= cond.length; ++i) {
800+
out_offsets[i] = left_offsets[i] - base;
801+
}
802+
803+
auto left_data_length = left_offsets[left.length] - base;
789804
ARROW_ASSIGN_OR_RAISE(out_data->buffers[2], ctx->Allocate(left_data_length));
790-
std::memcpy(out_data->buffers[2]->mutable_data(), left_data, left_data_length);
805+
std::memcpy(out_data->buffers[2]->mutable_data(), left_data + base,
806+
left_data_length);
791807
return Status::OK();
792808
}
793809

cpp/src/arrow/compute/kernels/scalar_if_else_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,8 +611,8 @@ TYPED_TEST(TestIfElseBaseBinary, IfElseBaseBinaryRand) {
611611
TYPED_TEST(TestIfElseBaseBinary, IfElseBaseBinarySliced) {
612612
auto type = TypeTraits<TypeParam>::type_singleton();
613613

614-
auto full_arr = ArrayFromJSON(type, R"([null, "x", "x", null, "x", "x"])");
615-
auto sliced = full_arr->Slice(3);
614+
auto full_arr = ArrayFromJSON(type, R"(["not used", null, "x", "x"])");
615+
auto sliced = full_arr->Slice(1);
616616

617617
auto cond_asa = ArrayFromJSON(boolean(), "[true, false, false]");
618618
ASSERT_OK_AND_ASSIGN(

0 commit comments

Comments
 (0)