| 51 | } |
| 52 | |
| 53 | Result<std::span<CompressedChunkLocation>> ChunkedIndexMapper::LogicalToPhysical() { |
| 54 | // Check that indices would fall in bounds for CompressedChunkLocation |
| 55 | if (ARROW_PREDICT_FALSE(chunk_lengths_.size() > |
| 56 | CompressedChunkLocation::kMaxChunkIndex + 1)) { |
| 57 | return Status::NotImplemented("Chunked array has more than ", |
| 58 | CompressedChunkLocation::kMaxChunkIndex + 1, " chunks"); |
| 59 | } |
| 60 | for (int64_t chunk_length : chunk_lengths_) { |
| 61 | if (ARROW_PREDICT_FALSE(static_cast<uint64_t>(chunk_length) > |
| 62 | CompressedChunkLocation::kMaxIndexInChunk + 1)) { |
| 63 | return Status::NotImplemented("Individual chunk in chunked array has more than ", |
| 64 | CompressedChunkLocation::kMaxIndexInChunk + 1, |
| 65 | " elements"); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | const int64_t num_indices = static_cast<int64_t>(indices_.size()); |
| 70 | DCHECK_EQ(num_indices, std::accumulate(chunk_lengths_.begin(), chunk_lengths_.end(), |
| 71 | static_cast<int64_t>(0))); |
| 72 | CompressedChunkLocation* physical_begin = |
| 73 | reinterpret_cast<CompressedChunkLocation*>(indices_.data()); |
| 74 | DCHECK_EQ(physical_begin + num_indices, reinterpret_cast<CompressedChunkLocation*>( |
| 75 | indices_.data() + indices_.size())); |
| 76 | |
| 77 | int64_t chunk_offset = 0; |
| 78 | for (int64_t chunk_index = 0; chunk_index < static_cast<int64_t>(chunk_lengths_.size()); |
| 79 | ++chunk_index) { |
| 80 | const int64_t chunk_length = chunk_lengths_[chunk_index]; |
| 81 | for (int64_t i = 0; i < chunk_length; ++i) { |
| 82 | // Logical indices are expected to be chunk-partitioned, which avoids costly |
| 83 | // chunked index resolution. |
| 84 | DCHECK_GE(indices_[chunk_offset + i], static_cast<uint64_t>(chunk_offset)); |
| 85 | DCHECK_LT(indices_[chunk_offset + i], |
| 86 | static_cast<uint64_t>(chunk_offset + chunk_length)); |
| 87 | physical_begin[chunk_offset + i] = CompressedChunkLocation{ |
| 88 | static_cast<uint64_t>(chunk_index), |
| 89 | indices_[chunk_offset + i] - static_cast<uint64_t>(chunk_offset)}; |
| 90 | } |
| 91 | chunk_offset += chunk_length; |
| 92 | } |
| 93 | |
| 94 | return std::span<CompressedChunkLocation>{physical_begin, physical_begin + num_indices}; |
| 95 | } |
| 96 | |
| 97 | Status ChunkedIndexMapper::PhysicalToLogical() { |
| 98 | std::vector<int64_t> chunk_offsets(chunk_lengths_.size()); |
nothing calls this directly
no test coverage detected