jayceslesar commented on code in PR #1995:
URL: https://github.com/apache/iceberg-python/pull/1995#discussion_r2123977100


##########
pyiceberg/io/pyarrow.py:
##########
@@ -1644,7 +1607,28 @@ def to_record_batches(self, tasks: 
Iterable[FileScanTask]) -> Iterator[pa.Record
             ValueError: When a field type in the file cannot be projected to 
the schema type
         """
         deletes_per_file = _read_all_delete_files(self._io, tasks)
-        return self._record_batches_from_scan_tasks_and_deletes(tasks, 
deletes_per_file)
+
+        total_row_count = 0
+        executor = ExecutorFactory.get_or_create()
+
+        limit_reached = False
+        for batches in executor.map(
+            lambda task: 
list(self._record_batches_from_scan_tasks_and_deletes([task], 
deletes_per_file)), tasks
+        ):
+            for batch in batches:
+                current_batch_size = len(batch)
+                if self._limit is not None and total_row_count + 
current_batch_size >= self._limit:
+                    yield batch.slice(0, self._limit - total_row_count)
+
+                    # This break will also cancel all running tasks
+                    limit_reached = True
+                    break
+
+                yield batch
+                total_row_count += current_batch_size
+
+            if limit_reached:
+                break

Review Comment:
   🤩



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to