Skip to content

Commit 76b4822

Browse files
committed
1 parent 821ab9c commit 76b4822

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

pyiceberg/io/pyarrow.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,8 +1464,10 @@ def project_batches(self, tasks: Iterable[FileScanTask]) -> Iterator[pa.RecordBa
14641464
def _project_batches_from_scan_tasks_and_deletes(
14651465
self, tasks: Iterable[FileScanTask], deletes_per_file: Dict[str, List[ChunkedArray]]
14661466
) -> Iterator[pa.RecordBatch]:
1467-
limit = self._limit
1467+
total_row_count = 0
14681468
for task in tasks:
1469+
if self._limit is not None and total_row_count >= self._limit:
1470+
break
14691471
batches = _task_to_record_batches(
14701472
self._fs,
14711473
task,
@@ -1478,12 +1480,13 @@ def _project_batches_from_scan_tasks_and_deletes(
14781480
self._use_large_types,
14791481
)
14801482
for batch in batches:
1481-
if limit is not None:
1482-
if len(batch) >= limit:
1483-
yield batch.slice(0, limit)
1483+
if self._limit is not None:
1484+
if total_row_count >= self._limit:
14841485
break
1485-
limit -= len(batch)
1486+
elif total_row_count + len(batch) >= self._limit:
1487+
batch = batch.slice(0, self._limit - total_row_count)
14861488
yield batch
1489+
total_row_count += len(batch)
14871490

14881491

14891492
@deprecated(

0 commit comments

Comments
 (0)