-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Open
mapleFU
wants to merge
6
commits into
apache:main
Choose a base branch
from
mapleFU:parquet/list-view-writing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
05f4c39
finish the path part impl
mapleFU f418244
Merge branch 'main' into parquet/list-view-writing
mapleFU f5cac8c
add test in path_internal_test
mapleFU 409a4ae
update schema test
mapleFU 47f7617
Merge branch 'main' into parquet/list-view-writing
mapleFU 20f01cd
Merge branch 'main' into parquet/list-view-writing
mapleFU File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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_; } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.: