Repository navigation
GH-51612: [C++] Fix list_view to list cast #51647
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?
Changes from all commits
3c18db5
eada049
c0df225
6f69464
4d54254
d20e1be
5a3761c
9d6030c
d357d8b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ | |
| #include "arrow/compute/kernels/scalar_cast_internal.h" | ||
| #include "arrow/util/bitmap_ops.h" | ||
| #include "arrow/util/int_util.h" | ||
| #include "arrow/util/list_util.h" | ||
| #include "arrow/util/logging_internal.h" | ||
|
|
||
| namespace arrow { | ||
|
|
@@ -105,7 +106,37 @@ struct CastList { | |
| return Status::OK(); | ||
| } | ||
|
|
||
| /// \brief Cast a list-view array to a (large)list array | ||
| /// | ||
| /// The values referenced by a list-view have to be gathered according to the | ||
| /// views' offsets and sizes, so the views' offsets buffer cannot be reused as | ||
| /// a list-offsets buffer (GH-51612). | ||
| static Status ExecListView(KernelContext* ctx, const ExecSpan& batch, ExecResult* out) { | ||
| const CastOptions& options = CastState::Get(ctx); | ||
| auto child_type = checked_cast<const DestType&>(*out->type()).value_type(); | ||
|
|
||
| ARROW_ASSIGN_OR_RAISE(std::shared_ptr<ArrayData> list_data, | ||
| list_util::internal::ListFromListView( | ||
| batch[0].array, DestType::type_id, ctx->memory_pool())); | ||
|
|
||
| ARROW_ASSIGN_OR_RAISE(Datum cast_values, Cast(list_data->child_data[0], child_type, | ||
| options, ctx->exec_context())); | ||
| DCHECK(cast_values.is_array()); | ||
|
|
||
| ArrayData* out_array = out->array_data().get(); | ||
| out_array->buffers[0] = std::move(list_data->buffers[0]); | ||
| out_array->buffers[1] = std::move(list_data->buffers[1]); | ||
| out_array->null_count.store(list_data->null_count.load()); | ||
| out_array->offset = list_data->offset; | ||
| out_array->child_data.push_back(cast_values.array()); | ||
| return Status::OK(); | ||
| } | ||
|
|
||
| static Status Exec(KernelContext* ctx, const ExecSpan& batch, ExecResult* out) { | ||
| if constexpr (is_list_view(SrcType::type_id)) { | ||
| return ExecListView(ctx, batch, out); | ||
| } | ||
|
|
||
|
Comment on lines
+136
to
+139
Contributor
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. This is a weird short-circuit for this logic that is meant to be generic for nested arrays. It would make more sense to have a branch around From those values you can decide to output a list-view or a *list. Always returning list is going to be weird (i.e. list-view in, list out). |
||
| const CastOptions& options = CastState::Get(ctx); | ||
|
|
||
| auto child_type = checked_cast<const DestType&>(*out->type()).value_type(); | ||
|
|
||
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 more common order is a function that takes dynamically typed values to delegate to the statically typed (templated/specialized). Here the opposite is happening.
This template has the types already worked out, but then it delegates to a function that is going to switch on the type ids again.