| 408 | |
| 409 | template <typename DestListType, typename SrcListViewType> |
| 410 | Result<std::shared_ptr<ArrayData>> ListFromListViewImpl( |
| 411 | const std::shared_ptr<ArrayData>& list_view_data, MemoryPool* pool) { |
| 412 | static_assert( |
| 413 | std::is_same<typename SrcListViewType::offset_type, |
| 414 | typename DestListType::offset_type>::value, |
| 415 | "Offset types between list type and list-view type are expected to match"); |
| 416 | using offset_type = typename DestListType::offset_type; |
| 417 | using ListBuilderType = typename TypeTraits<DestListType>::BuilderType; |
| 418 | |
| 419 | const auto& list_view_type = |
| 420 | checked_cast<const SrcListViewType&>(*list_view_data->type); |
| 421 | const auto& value_type = list_view_type.value_type(); |
| 422 | const auto list_type = std::make_shared<DestListType>(value_type); |
| 423 | |
| 424 | ARROW_ASSIGN_OR_RAISE(auto sum_of_list_view_sizes, |
| 425 | list_util::internal::SumOfLogicalListSizes(*list_view_data)); |
| 426 | ARROW_ASSIGN_OR_RAISE(std::shared_ptr<ArrayBuilder> value_builder, |
| 427 | MakeBuilder(value_type, pool)); |
| 428 | RETURN_NOT_OK(value_builder->Reserve(sum_of_list_view_sizes)); |
| 429 | auto list_builder = std::make_shared<ListBuilderType>(pool, value_builder, list_type); |
| 430 | RETURN_NOT_OK(list_builder->Reserve(list_view_data->length)); |
| 431 | |
| 432 | ArraySpan values{*list_view_data->child_data[0]}; |
| 433 | const auto* in_validity_bitmap = list_view_data->GetValues<uint8_t>(0); |
| 434 | const auto* in_offsets = list_view_data->GetValues<offset_type>(1); |
| 435 | const auto* in_sizes = list_view_data->GetValues<offset_type>(2); |
| 436 | for (int64_t i = 0; i < list_view_data->length; ++i) { |
| 437 | const bool is_valid = |
| 438 | !in_validity_bitmap || |
| 439 | bit_util::GetBit(in_validity_bitmap, list_view_data->offset + i); |
| 440 | const int64_t size = is_valid ? in_sizes[i] : 0; |
| 441 | RETURN_NOT_OK(list_builder->Append(is_valid, size)); |
| 442 | RETURN_NOT_OK(value_builder->AppendArraySlice(values, in_offsets[i], size)); |
| 443 | } |
| 444 | std::shared_ptr<ArrayData> list_array_data; |
| 445 | RETURN_NOT_OK(list_builder->FinishInternal(&list_array_data)); |
| 446 | return list_array_data; |
| 447 | } |
| 448 | |
| 449 | } // namespace |
| 450 |
nothing calls this directly
no test coverage detected