Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 4.3k
GH-38849: [C++][Parquet]: Add support for list view and large list view#38850
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
05f4c39f418244f5cac8c409a4ae47f761720f01cdFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -450,6 +450,17 @@ struct FixedSizedRangeSelector { | ||
| int list_size; | ||
| }; | ||
| template <typename OffsetType> | ||
| struct VarRangeViewSelector { | ||
| ElementRange GetRange(int64_t index) const { | ||
| return ElementRange{offsets[index], offsets[index] + sizes[index]}; | ||
| } | ||
| // Either int32_t* or int64_t*. | ||
| const OffsetType* offsets; | ||
| const OffsetType* sizes; | ||
| }; | ||
| // An intermediate node that handles null values. | ||
| class NullableNode { | ||
| public: | ||
| @@ -510,16 +521,18 @@ class NullableNode { | ||
| using ListNode = ListPathNode<VarRangeSelector<int32_t>>; | ||
| using LargeListNode = ListPathNode<VarRangeSelector<int64_t>>; | ||
| using ListViewNode = ListPathNode<VarRangeViewSelector<int32_t>>; | ||
| using LargeListViewNode = ListPathNode<VarRangeViewSelector<int64_t>>; | ||
| using FixedSizeListNode = ListPathNode<FixedSizedRangeSelector>; | ||
| // Contains static information derived from traversing the schema. | ||
| struct PathInfo { | ||
| // The vectors are expected to the same length info. | ||
| // Note index order matters here. | ||
| using Node = | ||
| std::variant<NullableTerminalNode, ListNode, LargeListNode, FixedSizeListNode, | ||
| NullableNode, AllPresentTerminalNode, AllNullsTerminalNode>; | ||
| using Node = std::variant<NullableTerminalNode, ListNode, LargeListNode, ListViewNode, | ||
| LargeListViewNode, FixedSizeListNode, NullableNode, | ||
| AllPresentTerminalNode, AllNullsTerminalNode>; | ||
| std::vector<Node> path; | ||
| std::shared_ptr<Array> primitive_array; | ||
| @@ -579,15 +592,21 @@ Status WritePath(ElementRange root_range, PathInfo* path_info, | ||
| IterationResult operator()(NullableNode& node) { | ||
| return node.Run(stack_position, stack_position + 1, context); | ||
| } | ||
| IterationResult operator()(ListNode& node) { | ||
| return node.Run(stack_position, stack_position + 1, context); | ||
| } | ||
| IterationResult operator()(NullableTerminalNode& node) { | ||
| return node.Run(*stack_position, context); | ||
| } | ||
| IterationResult operator()(ListNode& node) { | ||
| return node.Run(stack_position, stack_position + 1, context); | ||
| } | ||
| IterationResult operator()(FixedSizeListNode& node) { | ||
| return node.Run(stack_position, stack_position + 1, context); | ||
| } | ||
| IterationResult operator()(ListViewNode& node) { | ||
| return node.Run(stack_position, stack_position + 1, context); | ||
| } | ||
| IterationResult operator()(LargeListViewNode& node) { | ||
| return node.Run(stack_position, stack_position + 1, context); | ||
| } | ||
| IterationResult operator()(AllPresentTerminalNode& node) { | ||
| return node.Run(*stack_position, context); | ||
| } | ||
| @@ -651,6 +670,8 @@ struct FixupVisitor { | ||
| void operator()(ListNode& node) { HandleListNode(node); } | ||
| void operator()(LargeListNode& node) { HandleListNode(node); } | ||
| void operator()(FixedSizeListNode& node) { HandleListNode(node); } | ||
| void operator()(ListViewNode& node) { HandleListNode(node); } | ||
| void operator()(LargeListViewNode& node) { HandleListNode(node); } | ||
| // For non-list intermediate nodes. | ||
| template <typename T> | ||
| @@ -724,19 +745,31 @@ class PathBuilder { | ||
| template <typename T> | ||
| ::arrow::enable_if_t<std::is_same<::arrow::ListArray, T>::value || | ||
| std::is_same<::arrow::LargeListArray, T>::value, | ||
| std::is_same<::arrow::LargeListArray, T>::value || | ||
| std::is_same<::arrow::ListViewArray, T>::value || | ||
| std::is_same<::arrow::LargeListViewArray, T>::value, | ||
| Status> | ||
| Visit(const T& array) { | ||
| MaybeAddNullable(array); | ||
| // Increment necessary due to empty lists. | ||
| info_.max_def_level++; | ||
| info_.max_rep_level++; | ||
| // raw_value_offsets() accounts for any slice offset. | ||
| ListPathNode<VarRangeSelector<typename T::offset_type>> node( | ||
| VarRangeSelector<typename T::offset_type>{array.raw_value_offsets()}, | ||
| info_.max_rep_level, info_.max_def_level - 1); | ||
| info_.path.emplace_back(std::move(node)); | ||
| nullable_in_parent_ = array.list_type()->value_field()->nullable(); | ||
| // raw_value_offsets() and raw_value_sizes() accounts for any slice offset/size. | ||
| if constexpr (std::is_same<::arrow::ListViewArray, T>::value || | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use | ||
| std::is_same<::arrow::LargeListViewArray, T>::value) { | ||
| ListPathNode<VarRangeViewSelector<typename T::offset_type>> node( | ||
| VarRangeViewSelector<typename T::offset_type>{array.raw_value_offsets(), | ||
| array.raw_value_sizes()}, | ||
| info_.max_rep_level, info_.max_def_level - 1); | ||
| info_.path.emplace_back(std::move(node)); | ||
| nullable_in_parent_ = array.list_view_type()->value_field()->nullable(); | ||
| } else { | ||
| ListPathNode<VarRangeSelector<typename T::offset_type>> node( | ||
| VarRangeSelector<typename T::offset_type>{array.raw_value_offsets()}, | ||
| info_.max_rep_level, info_.max_def_level - 1); | ||
| info_.path.emplace_back(std::move(node)); | ||
| nullable_in_parent_ = array.list_type()->value_field()->nullable(); | ||
| } | ||
| return VisitInline(*array.values()); | ||
| } | ||
| @@ -830,8 +863,6 @@ class PathBuilder { | ||
| // Types not yet supported in Parquet. | ||
| NOT_IMPLEMENTED_VISIT(Union) | ||
| NOT_IMPLEMENTED_VISIT(RunEndEncoded); | ||
| NOT_IMPLEMENTED_VISIT(ListView); | ||
| NOT_IMPLEMENTED_VISIT(LargeListView); | ||
| #undef NOT_IMPLEMENTED_VISIT | ||
| std::vector<PathInfo>& paths() { return paths_; } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only thing that changes below is the list factory function, this could perhaps be factored out (also with
list_cast_fnsbelow), e.g.: