| 382 | |
| 383 | template <typename ArrayType, typename offset_type = typename ArrayType::offset_type> |
| 384 | Status GetZeroBasedListViewOffsets(const ArrayType& array, |
| 385 | std::shared_ptr<Buffer>* out_value_offsets, |
| 386 | offset_type* out_min_offset, |
| 387 | offset_type* out_max_end) { |
| 388 | auto offsets = array.value_offsets(); |
| 389 | |
| 390 | const int64_t required_bytes = sizeof(offset_type) * array.length(); |
| 391 | if (array.offset() != 0) { |
| 392 | // If we have a non-zero offset, it's likely that the smallest offset is |
| 393 | // not zero. We must a) create a new offsets array with shifted offsets and |
| 394 | // b) slice the values array accordingly. |
| 395 | if (!array.data()->buffers[1]->is_cpu()) { |
| 396 | return Status::NotImplemented("Rebasing non-CPU list view offsets"); |
| 397 | } |
| 398 | |
| 399 | ARROW_ASSIGN_OR_RAISE(auto shifted_offsets, |
| 400 | AllocateBuffer(required_bytes, options_.memory_pool)); |
| 401 | offset_type min_offset = 0; |
| 402 | offset_type max_end = 0; |
| 403 | if (array.length() > 0) { |
| 404 | min_offset = std::numeric_limits<offset_type>::max(); |
| 405 | for (int i = 0; i < array.length(); ++i) { |
| 406 | min_offset = std::min(min_offset, array.value_offset(i)); |
| 407 | max_end = std::max(max_end, array.value_offset(i) + array.value_length(i)); |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | auto* dest_offsets = shifted_offsets->mutable_data_as<offset_type>(); |
| 412 | |
| 413 | for (int i = 0; i < array.length(); ++i) { |
| 414 | dest_offsets[i] = array.value_offset(i) - min_offset; |
| 415 | } |
| 416 | *out_min_offset = min_offset; |
| 417 | *out_max_end = max_end; |
| 418 | offsets = std::move(shifted_offsets); |
| 419 | } else { |
| 420 | // ARROW-6046: Slice offsets to used extent, in case we have a truncated |
| 421 | // slice |
| 422 | if (offsets != nullptr && offsets->size() > required_bytes) { |
| 423 | offsets = SliceBuffer(offsets, 0, required_bytes); |
| 424 | } |
| 425 | *out_min_offset = 0; |
| 426 | *out_max_end = static_cast<offset_type>(array.values()->length()); |
| 427 | } |
| 428 | *out_value_offsets = std::move(offsets); |
| 429 | return Status::OK(); |
| 430 | } |
| 431 | |
| 432 | template <typename ArrayType, typename offset_type = typename ArrayType::offset_type> |
| 433 | Status GetListViewSizes(const ArrayType& array, |
nothing calls this directly
no test coverage detected