Skip to content

Commit 7d0f8a0

Browse files
committed
address review
1 parent 7863a3a commit 7d0f8a0

2 files changed

Lines changed: 47 additions & 44 deletions

File tree

cpp/src/parquet/arrow/arrow_reader_writer_test.cc

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
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

33493377
TEST(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-
33973398
TEST(ArrowReadWrite, FixedSizeList) {
33983399
using ::arrow::field;
33993400
using ::arrow::fixed_size_list;

cpp/src/parquet/arrow/path_internal.cc

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -405,13 +405,15 @@ class ListPathNode {
405405
// def_levels entered first.
406406
break;
407407
}
408-
if constexpr (RangeSelector::kCheckContiguous) {
408+
// FillForLast extends child_range by updating only its end. Non-contiguous
409+
// selectors must split at gaps.
410+
if constexpr (RangeSelector::kContiguous) {
411+
DCHECK_EQ(size_check.start, child_range->end)
412+
<< size_check.start << " != " << child_range->end;
413+
} else {
409414
if (size_check.start != child_range->end) {
410415
break;
411416
}
412-
} else {
413-
DCHECK_EQ(size_check.start, child_range->end)
414-
<< size_check.start << " != " << child_range->end;
415417
}
416418
// This is the start of a new list. We can be sure it only applies
417419
// to the previous list (and doesn't jump to the start of any list
@@ -439,7 +441,7 @@ class ListPathNode {
439441

440442
template <typename OffsetType>
441443
struct VarRangeSelector {
442-
static constexpr bool kCheckContiguous = false;
444+
static constexpr bool kContiguous = true;
443445

444446
ElementRange GetRange(int64_t index) const {
445447
return ElementRange{.start = offsets[index], .end = offsets[index + 1]};
@@ -451,7 +453,7 @@ struct VarRangeSelector {
451453

452454
template <typename OffsetType>
453455
struct ListViewRangeSelector {
454-
static constexpr bool kCheckContiguous = true;
456+
static constexpr bool kContiguous = false;
455457

456458
ElementRange GetRange(int64_t index) const {
457459
const int64_t start = offsets[index];
@@ -463,7 +465,7 @@ struct ListViewRangeSelector {
463465
};
464466

465467
struct FixedSizedRangeSelector {
466-
static constexpr bool kCheckContiguous = false;
468+
static constexpr bool kContiguous = true;
467469

468470
ElementRange GetRange(int64_t index) const {
469471
int64_t start = index * list_size;

0 commit comments

Comments
 (0)