diff --git a/cpp/src/lance/io/exec/limit.cc b/cpp/src/lance/io/exec/limit.cc index 07dbd8dc3a..1467020463 100644 --- a/cpp/src/lance/io/exec/limit.cc +++ b/cpp/src/lance/io/exec/limit.cc @@ -50,18 +50,18 @@ ::arrow::Result Limit::Next() { if (batch.eof()) { return batch; } - // Find intersection of two range (offset, offset + limit) and (seen + batch_size). - auto num_rows = batch.batch->num_rows(); + // Find intersection of two ranges (offset, offset + limit) and (seen, seen + batch_size). + auto batch_size = batch.batch->num_rows(); auto left = std::max(offset_, seen_); - auto right = std::min(seen_ + num_rows, offset_ + limit_); + auto right = std::min(seen_ + batch_size, offset_ + limit_); std::shared_ptr<::arrow::RecordBatch> record_batch; if (left < right) { record_batch = batch.batch->Slice(left - seen_, right - left); } else { - /// No interaction, skip the whole batch. + /// No intersection, skip the whole batch. ARROW_ASSIGN_OR_RAISE(record_batch, ::arrow::RecordBatch::MakeEmpty(batch.batch->schema())); } - seen_ += num_rows; + seen_ += batch_size; return ScanBatch{record_batch, batch.batch_id}; }