2828#include < functional>
2929#include < set>
3030#include < sstream>
31+ #include < type_traits>
3132#include < utility>
3233#include < vector>
3334
@@ -3325,25 +3326,52 @@ TEST(ArrowReadWrite, LargeList) {
33253326 }
33263327}
33273328
3328- TEST (ArrowReadWrite, ListView) {
3329+ template <typename ViewType>
3330+ requires ::arrow::is_list_view_type<ViewType>::value
3331+ void CheckListViewRoundTrip (
3332+ const std::shared_ptr<ViewType>& view_type,
3333+ const std::shared_ptr<::arrow::DataType>& fallback_type,
3334+ const ArrowReaderProperties& reader_props = default_arrow_reader_properties ()) {
3335+ using ViewArrayType = typename ::arrow::TypeTraits<ViewType>::ArrayType;
3336+ using OffsetArrowType = typename ::arrow::TypeTraits<ViewType>::OffsetType;
3337+ using FallbackArrayType =
3338+ std::conditional_t <std::is_same_v<ViewType, ::arrow::ListViewType>,
3339+ ::arrow::ListArray, ::arrow::LargeListArray>;
3340+
33293341 auto values = ArrayFromJSON (::arrow::int32 (), " [1, 2, 3, 4, 5]" );
3330- auto offsets = ArrayFromJSON (::arrow::int32 (), " [3, 0, 5, 1]" );
3331- auto sizes = ArrayFromJSON (::arrow::int32 (), " [2, 1, 0, 2]" );
3332- ASSERT_OK_AND_ASSIGN (auto array, ::arrow::ListViewArray::FromArrays (
3333- ::arrow::list_view (::arrow::int32()), *offsets,
3334- *sizes, *values, default_memory_pool()));
3342+ auto offsets = ArrayFromJSON (::arrow::TypeTraits<OffsetArrowType>::type_singleton (),
3343+ " [3, 0, 5, 1]" );
3344+ auto sizes = ArrayFromJSON (::arrow::TypeTraits<OffsetArrowType>::type_singleton (),
3345+ " [2, 1, 0, 2]" );
3346+ ASSERT_OK_AND_ASSIGN (auto array,
3347+ ViewArrayType::FromArrays (view_type, *offsets, *sizes, *values,
3348+ default_memory_pool ()));
3349+
33353350 auto table = Table::Make (
33363351 ::arrow::schema ({::arrow::field (" root" , array->type (), false )}), {array});
33373352
33383353 auto props_store_schema = ArrowWriterProperties::Builder ().store_schema ()->build ();
33393354 CheckSimpleRoundtrip (table, 2 , props_store_schema);
33403355
33413356 ASSERT_OK_AND_ASSIGN (auto expected_array,
3342- ::arrow::ListArray::FromListView (*array, default_memory_pool()));
3357+ FallbackArrayType::FromListView (*array, default_memory_pool ()));
3358+
33433359 auto expected = Table::Make (
3344- ::arrow::schema ({::arrow::field (" root" , ::arrow::list (::arrow::int32 ()), false )}),
3345- {expected_array});
3346- CheckConfiguredRoundtrip (table, expected);
3360+ ::arrow::schema ({::arrow::field (" root" , fallback_type, false )}), {expected_array});
3361+ CheckConfiguredRoundtrip (table, expected, ::parquet::default_writer_properties (),
3362+ default_arrow_writer_properties (), reader_props);
3363+ }
3364+
3365+ TEST (ArrowReadWrite, ListView) {
3366+ CheckListViewRoundTrip (std::make_shared<::arrow::ListViewType>(::arrow::int32 ()),
3367+ ::arrow::list (::arrow::int32()));
3368+ }
3369+
3370+ TEST (ArrowReadWrite, LargeListView) {
3371+ ArrowReaderProperties reader_props;
3372+ reader_props.set_list_type (::arrow::Type::LARGE_LIST );
3373+ CheckListViewRoundTrip (std::make_shared<::arrow::LargeListViewType>(::arrow::int32 ()),
3374+ ::arrow::large_list (::arrow::int32()), reader_props);
33473375}
33483376
33493377TEST (ArrowReadWrite, EmptyListView) {
@@ -3367,33 +3395,6 @@ TEST(ArrowReadWrite, EmptyListView) {
33673395 ASSERT_EQ (0 , list_view.value_sizes ()->size ());
33683396}
33693397
3370- TEST (ArrowReadWrite, LargeListView) {
3371- auto values = ArrayFromJSON (::arrow::int32 (), " [1, 2, 3, 4, 5]" );
3372- auto offsets = ArrayFromJSON (::arrow::int64 (), " [3, 0, 5, 1]" );
3373- auto sizes = ArrayFromJSON (::arrow::int64 (), " [2, 1, 0, 2]" );
3374- auto element = ::arrow::field (" element" , ::arrow::int32 ());
3375- ASSERT_OK_AND_ASSIGN (auto array, ::arrow::LargeListViewArray::FromArrays (
3376- ::arrow::large_list_view (element), *offsets,
3377- *sizes, *values, default_memory_pool()));
3378- auto table = Table::Make (
3379- ::arrow::schema ({::arrow::field (" root" , array->type (), false )}), {array});
3380-
3381- auto props_store_schema = ArrowWriterProperties::Builder ().store_schema ()->build ();
3382- CheckSimpleRoundtrip (table, 2 , props_store_schema);
3383-
3384- ASSERT_OK_AND_ASSIGN (auto expected_array,
3385- ::arrow::LargeListArray::FromListView (
3386- checked_cast<const ::arrow::LargeListViewArray&>(*array),
3387- default_memory_pool()));
3388- auto expected = Table::Make (
3389- ::arrow::schema ({::arrow::field (" root" , ::arrow::large_list (element), false )}),
3390- {expected_array});
3391- ArrowReaderProperties reader_props;
3392- reader_props.set_list_type (::arrow::Type::LARGE_LIST );
3393- CheckConfiguredRoundtrip (table, expected, ::parquet::default_writer_properties (),
3394- default_arrow_writer_properties (), reader_props);
3395- }
3396-
33973398TEST (ArrowReadWrite, FixedSizeList) {
33983399 using ::arrow::field;
33993400 using ::arrow::fixed_size_list;
0 commit comments