Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cpp/src/arrow/compute/kernels/scalar_string_ascii.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2642,7 +2642,8 @@ struct SliceBytesTransform : StringSliceTransformBase {
// on the resulting slice lengths, so return a worst case estimate.
return input_bytes;
}
int64_t max_slice_bytes = (opt.stop - opt.start + opt.step - 1) / opt.step;
const int64_t stop = std::clamp(opt.stop, -input_bytes, input_bytes);
int64_t max_slice_bytes = (stop - opt.start + opt.step - 1) / opt.step;
return std::min(input_bytes, ninputs * std::max<int64_t>(0, max_slice_bytes));
}

Expand Down
7 changes: 7 additions & 0 deletions cpp/src/arrow/compute/kernels/scalar_string_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2702,6 +2702,13 @@ TYPED_TEST(TestBinaryKernels, SliceBytesBasic) {
}

TYPED_TEST(TestBinaryKernels, SliceBytesPosPos) {
SliceOptions options_default_stop{/*start=*/1};
const std::string long_input(300, 'x');
this->CheckUnary(
"binary_slice", this->template MakeArray<std::string>({"abcdef", long_input}),
this->template MakeArray<std::string>({"bcdef", std::string(299, 'x')}),
&options_default_stop);

SliceOptions options{2, 4};
this->CheckUnary(
"binary_slice",
Expand Down
Loading