dkp116 commented on code in PR #50366:
URL: https://github.com/apache/arrow/pull/50366#discussion_r3536429884
##########
cpp/src/arrow/array/array_test.cc:
##########
@@ -1137,6 +1137,55 @@ TEST_F(TestArray, TestBinaryViewAppendArraySlice) {
AssertArraysEqual(*src, *dst);
}
+TEST_F(TestArray, GetSpanRespectsOffset) {
+ std::vector<uint16_t> values = {1, 2, 3, 4, 5};
+
+ auto data_buffer = Buffer::Wrap(values);
+ auto data = ArrayData::Make(uint16(), 3, {nullptr, data_buffer}, 0, 1);
+ auto span = data->GetSpan<uint16_t>(1, 3);
+
+ EXPECT_EQ(span.size(), 3);
+
+ EXPECT_EQ(span[0], 2);
+
+ EXPECT_EQ(span[1], 3);
+
+ EXPECT_EQ(span[2], 4);
+}
+
+TEST_F(TestArray, GetMutableSpanRespectsOffset) {
+ std::vector<uint16_t> values = {10, 20, 30, 40, 50};
+
+ const int64_t nbytes = values.size() * sizeof(uint16_t);
+ ASSERT_OK_AND_ASSIGN(auto uniq_buffer, AllocateResizableBuffer(nbytes,
pool_));
+ memcpy(uniq_buffer->mutable_data(), values.data(), nbytes);
+
+ std::shared_ptr<Buffer> buffer(std::move(uniq_buffer));
Review Comment:
This returns an immutable Buffer so used this function for immutable GetSpan
test case, for mutable span test case I simplied using MutableBuffer type
--
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]