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
6 changes: 4 additions & 2 deletions cpp/src/arrow/compute/kernels/vector_pairwise.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,12 @@ Status PairwiseExecImpl(KernelContext* ctx, const ArraySpan& input,
}
result->null_count = null_count;
// prepare input span
// SetSlice overwrites offset. Keep the input's offset so a sliced
// array is not read from the start of the parent buffer.
ArraySpan left(input);
left.SetSlice(left_start, computed_length);
left.SetSlice(input.offset + left_start, computed_length);
ArraySpan right(input);
right.SetSlice(right_start, computed_length);
right.SetSlice(input.offset + right_start, computed_length);
// prepare output span
ArraySpan output_span;
output_span.SetMembers(*result);
Expand Down
20 changes: 20 additions & 0 deletions cpp/src/arrow/compute/kernels/vector_pairwise_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,26 @@ TEST_F(TestPairwiseDiff, Numeric) {
}
}

TEST_F(TestPairwiseDiff, SlicedInput) {
// Slice() keeps a nonzero offset into the parent buffer. The kernel
// used to treat that offset as zero and read values before the slice.
auto base = ArrayFromJSON(int64(), "[99, 1, 4, 9, 16, 88]");
auto sliced = base->Slice(1, 4);

{
PairwiseOptions options(1);
auto expected = ArrayFromJSON(int64(), "[null, 3, 5, 7]");
CheckVectorUnary("pairwise_diff", sliced, expected, &options);
CheckVectorUnary("pairwise_diff_checked", sliced, expected, &options);
}
{
PairwiseOptions options(-1);
auto expected = ArrayFromJSON(int64(), "[-3, -5, -7, null]");
CheckVectorUnary("pairwise_diff", sliced, expected, &options);
CheckVectorUnary("pairwise_diff_checked", sliced, expected, &options);
}
}

TEST_F(TestPairwiseDiff, Overflow) {
{
PairwiseOptions options(1);
Expand Down
Loading