| 377 | |
| 378 | template <typename DestListViewType, typename SrcListType> |
| 379 | Result<std::shared_ptr<ArrayData>> ListViewFromListImpl( |
| 380 | const std::shared_ptr<ArrayData>& list_data, MemoryPool* pool) { |
| 381 | static_assert( |
| 382 | std::is_same<typename SrcListType::offset_type, |
| 383 | typename DestListViewType::offset_type>::value, |
| 384 | "Offset types between list type and list-view type are expected to match"); |
| 385 | using offset_type = typename SrcListType::offset_type; |
| 386 | const auto& list_type = checked_cast<const SrcListType&>(*list_data->type); |
| 387 | |
| 388 | // To re-use the validity and offsets buffers, a sizes buffer with enough |
| 389 | // padding on the beginning is allocated and filled with the sizes after |
| 390 | // list_data->offset. |
| 391 | const int64_t buffer_length = list_data->offset + list_data->length; |
| 392 | ARROW_ASSIGN_OR_RAISE(auto sizes_buffer, |
| 393 | AllocateBuffer(buffer_length * sizeof(offset_type), pool)); |
| 394 | const auto* offsets = list_data->template GetValues<offset_type>(1, 0); |
| 395 | auto* sizes = sizes_buffer->mutable_data_as<offset_type>(); |
| 396 | // Zero the initial padding area to avoid leaking any data when buffers are |
| 397 | // sent over IPC or through the C Data interface. |
| 398 | memset(sizes, 0, list_data->offset * sizeof(offset_type)); |
| 399 | for (int64_t i = list_data->offset; i < buffer_length; i++) { |
| 400 | sizes[i] = offsets[i + 1] - offsets[i]; |
| 401 | } |
| 402 | BufferVector buffers = {list_data->buffers[0], list_data->buffers[1], |
| 403 | std::move(sizes_buffer)}; |
| 404 | |
| 405 | return ArrayData::Make(std::make_shared<DestListViewType>(list_type.value_type()), |
| 406 | list_data->length, std::move(buffers), |
| 407 | {list_data->child_data[0]}, list_data->null_count, |
| 408 | list_data->offset); |
| 409 | } |
| 410 | |
| 411 | template <typename DestListType, typename SrcListViewType> |
| 412 | Result<std::shared_ptr<ArrayData>> ListFromListViewImpl( |
nothing calls this directly
no test coverage detected