wjones127 commented on code in PR #37292:
URL: https://github.com/apache/arrow/pull/37292#discussion_r1301779157
##########
cpp/src/arrow/compute/kernels/scalar_cast_nested.cc:
##########
@@ -145,6 +153,135 @@ void AddListCast(CastFunction* func) {
DCHECK_OK(func->AddKernel(SrcType::type_id, std::move(kernel)));
}
+template <typename DestType>
+struct CastFixedToVarList {
+ using dest_offset_type = typename DestType::offset_type;
+
+ static Status Exec(KernelContext* ctx, const ExecSpan& batch, ExecResult*
out) {
+ const CastOptions& options = CastState::Get(ctx);
+
+ auto child_type = checked_cast<const DestType&>(*out->type()).value_type();
+
+ const ArraySpan& in_array = batch[0].array;
+
+ ArrayData* out_array = out->array_data().get();
+ ARROW_ASSIGN_OR_RAISE(out_array->buffers[0],
+ GetNullBitmapBuffer(in_array, ctx->memory_pool()));
+
+ const auto& in_type = checked_cast<const
FixedSizeListType&>(*in_array.type);
+ const int32_t list_size = in_type.list_size();
+
+ // Allocate a new offsets buffer
+ ARROW_ASSIGN_OR_RAISE(out_array->buffers[1],
+ ctx->Allocate(sizeof(dest_offset_type) *
(batch.length + 1)));
+ auto* offsets = out_array->GetMutableValues<dest_offset_type>(1);
+ dest_offset_type offset = 0;
+ for (int64_t i = 0; i <= batch.length; ++i) {
+ offsets[i] = offset;
+ offset += list_size;
+ }
+
+ // Handle values
+ std::shared_ptr<ArrayData> values = in_array.child_data[0].ToArrayData();
+ if (in_array.offset > 0 || (in_array.length * list_size < batch.length)) {
Review Comment:
Actually, I think the second condition might be unnecessary. The offsets
will already determine the end of the array, so we shouldn't need to slice the
values if there isn't an offset.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]