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-41183: [C++][Python] Expose recursive flatten for lists on list_flatten kernel function and pyarrow bindings#41295
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
Merged
felipecrv
merged 7 commits into
apache:main
from
ZhangHuiGui:expose_recursive_flatten_on_list_related_kernelApr 30, 2024
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7a5dfae
1. Expose recursive flatten for logical lists on list_flatten kernel …
ZhangHuiGui 4a9c94b
fix
ZhangHuiGui 6fdd0ee
fix comments and pyarrow's compile failure
ZhangHuiGui 81a909f
fix
ZhangHuiGui 402c225
fix doctest
ZhangHuiGui ce9947a
fix typo and grammar
ZhangHuiGui 4a08a14
add a test case
ZhangHuiGui File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
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
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
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 |
|---|---|---|
| @@ -23,6 +23,7 @@ | ||
| #include "arrow/compute/api_scalar.h" | ||
| #include "arrow/compute/kernels/common_internal.h" | ||
| #include "arrow/result.h" | ||
| #include "arrow/type_fwd.h" | ||
| #include "arrow/util/bit_block_counter.h" | ||
| #include "arrow/util/bit_util.h" | ||
| #include "arrow/util/bitmap_generate.h" | ||
| @@ -41,10 +42,17 @@ Status ListValueLength(KernelContext* ctx, const ExecSpan& batch, ExecResult* ou | ||
| const ArraySpan& arr = batch[0].array; | ||
| ArraySpan* out_arr = out->array_span_mutable(); | ||
| auto out_values = out_arr->GetValues<offset_type>(1); | ||
| const offset_type* offsets = arr.GetValues<offset_type>(1); | ||
| // Offsets are always well-defined and monotonic, even for null values | ||
| for (int64_t i = 0; i < arr.length; ++i) { | ||
| *out_values++ = offsets[i + 1] - offsets[i]; | ||
| if (is_list_view(*arr.type)) { | ||
| const auto* sizes = arr.GetValues<offset_type>(2); | ||
| if (arr.length > 0) { | ||
| memcpy(out_values, sizes, arr.length * sizeof(offset_type)); | ||
| } | ||
| } else { | ||
| const offset_type* offsets = arr.GetValues<offset_type>(1); | ||
| // Offsets are always well-defined and monotonic, even for null values | ||
| for (int64_t i = 0; i < arr.length; ++i) { | ||
| *out_values++ = offsets[i + 1] - offsets[i]; | ||
| } | ||
| } | ||
| return Status::OK(); | ||
| } | ||
| @@ -59,6 +67,30 @@ Status FixedSizeListValueLength(KernelContext* ctx, const ExecSpan& batch, | ||
| return Status::OK(); | ||
| } | ||
| template <typename InListType> | ||
| void AddListValueLengthKernel(ScalarFunction* func, | ||
| const std::shared_ptr<DataType>& out_type) { | ||
| auto in_type = {InputType(InListType::type_id)}; | ||
| ScalarKernel kernel(in_type, out_type, ListValueLength<InListType>); | ||
| DCHECK_OK(func->AddKernel(std::move(kernel))); | ||
| } | ||
felipecrv marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. | ||
| template <> | ||
| void AddListValueLengthKernel<FixedSizeListType>( | ||
| ScalarFunction* func, const std::shared_ptr<DataType>& out_type) { | ||
| auto in_type = {InputType(Type::FIXED_SIZE_LIST)}; | ||
| ScalarKernel kernel(in_type, out_type, FixedSizeListValueLength); | ||
| DCHECK_OK(func->AddKernel(std::move(kernel))); | ||
| } | ||
| void AddListValueLengthKernels(ScalarFunction* func) { | ||
| AddListValueLengthKernel<ListType>(func, int32()); | ||
| AddListValueLengthKernel<LargeListType>(func, int64()); | ||
| AddListValueLengthKernel<ListViewType>(func, int32()); | ||
| AddListValueLengthKernel<LargeListViewType>(func, int64()); | ||
| AddListValueLengthKernel<FixedSizeListType>(func, int32()); | ||
| } | ||
| const FunctionDoc list_value_length_doc{ | ||
| "Compute list lengths", | ||
| ("`lists` must have a list-like type.\n" | ||
| @@ -399,6 +431,8 @@ void AddListElementKernels(ScalarFunction* func) { | ||
| void AddListElementKernels(ScalarFunction* func) { | ||
| AddListElementKernels<ListType, ListElement>(func); | ||
| AddListElementKernels<LargeListType, ListElement>(func); | ||
| AddListElementKernels<ListViewType, ListElement>(func); | ||
| AddListElementKernels<LargeListViewType, ListElement>(func); | ||
| AddListElementKernels<FixedSizeListType, FixedSizeListElement>(func); | ||
| } | ||
| @@ -824,12 +858,7 @@ const FunctionDoc map_lookup_doc{ | ||
| void RegisterScalarNested(FunctionRegistry* registry) { | ||
| auto list_value_length = std::make_shared<ScalarFunction>( | ||
| "list_value_length", Arity::Unary(), list_value_length_doc); | ||
| DCHECK_OK(list_value_length->AddKernel({InputType(Type::LIST)}, int32(), | ||
| ListValueLength<ListType>)); | ||
| DCHECK_OK(list_value_length->AddKernel({InputType(Type::FIXED_SIZE_LIST)}, int32(), | ||
| FixedSizeListValueLength)); | ||
| DCHECK_OK(list_value_length->AddKernel({InputType(Type::LARGE_LIST)}, int64(), | ||
| ListValueLength<LargeListType>)); | ||
| AddListValueLengthKernels(list_value_length.get()); | ||
| DCHECK_OK(registry->AddFunction(std::move(list_value_length))); | ||
| auto list_element = | ||
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
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Uh oh!
There was an error while loading. Please reload this page.