pitrou commented on code in PR #52451:
URL: https://github.com/apache/arrow/pull/52451#discussion_r4259032996
##########
cpp/src/arrow/compute/kernels/scalar_string_ascii.cc:
##########
@@ -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);
Review Comment:
Can you add a comment explaining the motivation for this?
##########
cpp/src/arrow/compute/kernels/scalar_string_test.cc:
##########
@@ -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);
Review Comment:
I think we can add a couple other interesting cases:
* start=1, step=5
* start=-1, stop=INT64_MIN
* start=-1, stop=INT64_MIN, step=-5
--
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]