diff --git a/cpp/src/arrow/compute/kernels/chunked_internal.cc b/cpp/src/arrow/compute/kernels/chunked_internal.cc index 8f72acc878162..e72b8e1f5bfb7 100644 --- a/cpp/src/arrow/compute/kernels/chunked_internal.cc +++ b/cpp/src/arrow/compute/kernels/chunked_internal.cc @@ -67,6 +67,8 @@ ChunkedIndexMapper::LogicalToPhysical() { } const int64_t num_indices = static_cast(indices_end_ - indices_begin_); + DCHECK_EQ(num_indices, std::accumulate(chunk_lengths_.begin(), chunk_lengths_.end(), + static_cast(0))); CompressedChunkLocation* physical_begin = reinterpret_cast(indices_begin_); DCHECK_EQ(physical_begin + num_indices, @@ -77,6 +79,8 @@ ChunkedIndexMapper::LogicalToPhysical() { ++chunk_index) { const int64_t chunk_length = chunk_lengths_[chunk_index]; for (int64_t i = 0; i < chunk_length; ++i) { + // Logical indices are expected to be chunk-partitioned, which avoids costly + // chunked index resolution. DCHECK_GE(indices_begin_[chunk_offset + i], static_cast(chunk_offset)); DCHECK_LT(indices_begin_[chunk_offset + i], static_cast(chunk_offset + chunk_length));