@@ -316,6 +316,83 @@ TEST(ByteRanges, FixedSizeList) {
316316 CheckBufferRanges (list_arr_with_nulls->Slice (4 , 1 ), {{0 , 0 , 1 }, {1 , 1 , 1 }, {2 , 8 , 2 }});
317317}
318318
319+ TEST (ByteRanges, StringViewType) {
320+ std::shared_ptr<Array> str_view_arr = ArrayFromJSON (
321+ utf8_view (), R"( ["short", "a longer string that requires a buffer"])" );
322+ // First buffer is validity (null in this case), second is views (16 bytes per view),
323+ // third is the data buffer for long strings
324+ CheckBufferRanges (str_view_arr, {{0 , 0 , 32 }, {1 , 0 , 38 }});
325+
326+ std::shared_ptr<Array> str_view_with_nulls = ArrayFromJSON (
327+ utf8_view (), R"( ["short", null, "another long string that requires a buffer"])" );
328+ CheckBufferRanges (str_view_with_nulls, {{0 , 0 , 1 }, {1 , 0 , 48 }, {2 , 0 , 42 }});
329+
330+ CheckBufferRanges (str_view_arr->Slice (1 , 1 ), {{0 , 16 , 16 }, {1 , 0 , 38 }});
331+ CheckBufferRanges (str_view_arr->Slice (0 , 1 ), {{0 , 0 , 16 }, {1 , 0 , 38 }});
332+ CheckBufferRanges (str_view_with_nulls->Slice (2 , 1 ),
333+ {{0 , 0 , 1 }, {1 , 32 , 16 }, {2 , 0 , 42 }});
334+ }
335+
336+ TEST (ByteRanges, BinaryViewType) {
337+ std::shared_ptr<Array> bin_view_arr =
338+ ArrayFromJSON (binary_view (), R"( ["ABCD", "EFGHIJKLMNOPQRSTUVWXYZ"])" );
339+ // Similar to string view: views buffer (16 bytes per view), then data buffers
340+ CheckBufferRanges (bin_view_arr, {{0 , 0 , 32 }, {1 , 0 , 22 }});
341+
342+ std::shared_ptr<Array> bin_view_with_nulls =
343+ ArrayFromJSON (binary_view (), R"( ["AB", null, "CDEFGHIJKLMNOPQRSTUVWXYZ"])" );
344+ CheckBufferRanges (bin_view_with_nulls, {{0 , 0 , 1 }, {1 , 0 , 48 }, {2 , 0 , 24 }});
345+
346+ CheckBufferRanges (bin_view_arr->Slice (1 , 1 ), {{0 , 16 , 16 }, {1 , 0 , 22 }});
347+ CheckBufferRanges (bin_view_with_nulls->Slice (2 , 1 ),
348+ {{0 , 0 , 1 }, {1 , 32 , 16 }, {2 , 0 , 24 }});
349+ }
350+
351+ using ListViewArrowTypes = ::testing::Types<ListViewType, LargeListViewType>;
352+ template <typename Type>
353+ class ByteRangesListView : public ::testing::Test {};
354+ TYPED_TEST_SUITE (ByteRangesListView, ListViewArrowTypes);
355+
356+ TYPED_TEST (ByteRangesListView, Basic) {
357+ using offset_type = typename TypeParam::offset_type;
358+ std::shared_ptr<DataType> type = std::make_shared<TypeParam>(int32 ());
359+ std::shared_ptr<Array> list_view_arr = ArrayFromJSON (type, " [[1, 2], [3], [0]]" );
360+ // Offsets buffer, sizes buffer, then child data
361+ CheckBufferRanges (
362+ list_view_arr,
363+ {{0 , 0 , 3 * sizeof (offset_type)}, {1 , 0 , 3 * sizeof (offset_type)}, {2 , 0 , 16 }});
364+
365+ std::shared_ptr<Array> list_view_with_nulls =
366+ ArrayFromJSON (type, " [[1, 2], null, [3, 4, 5]]" );
367+ CheckBufferRanges (list_view_with_nulls, {{0 , 0 , 1 },
368+ {1 , 0 , 3 * sizeof (offset_type)},
369+ {2 , 0 , 3 * sizeof (offset_type)},
370+ {3 , 0 , 20 }});
371+ CheckBufferRanges (list_view_arr->Slice (2 , 1 ),
372+ {{0 , 2 * sizeof (offset_type), sizeof (offset_type)},
373+ {1 , 2 * sizeof (offset_type), sizeof (offset_type)},
374+ {2 , 0 , 16 }});
375+ CheckBufferRanges (list_view_with_nulls->Slice (2 , 1 ),
376+ {{0 , 0 , 1 },
377+ {1 , 2 * sizeof (offset_type), sizeof (offset_type)},
378+ {2 , 2 * sizeof (offset_type), sizeof (offset_type)},
379+ {3 , 0 , 20 }});
380+ }
381+
382+ TYPED_TEST (ByteRangesListView, NestedListView) {
383+ using offset_type = typename TypeParam::offset_type;
384+ std::shared_ptr<DataType> type =
385+ std::make_shared<TypeParam>(std::make_shared<TypeParam>(int32 ()));
386+ std::shared_ptr<Array> list_view_arr =
387+ ArrayFromJSON (type, " [[[1], [2, 3]], [[4, 5, 6]], [[7]]]" );
388+ // Parent offsets, parent sizes, child offsets, child sizes, grandchild data
389+ CheckBufferRanges (list_view_arr, {{0 , 0 , 3 * sizeof (offset_type)},
390+ {1 , 0 , 3 * sizeof (offset_type)},
391+ {2 , 0 , 4 * sizeof (offset_type)},
392+ {3 , 0 , 4 * sizeof (offset_type)},
393+ {4 , 0 , 28 }});
394+ }
395+
319396TEST (ByteRanges, Map) {
320397 std::shared_ptr<Array> map_arr = ArrayFromJSON (
321398 map (utf8 (), uint16 ()), R"( [[["x", 1], ["y", 2]], [["x", 3], ["y", 4]]])" );
0 commit comments