Skip to content

Core: Stream Arrow batch readers without read-ahead - #4492

Open
Anurag-S1ngh wants to merge 1 commit into
apache:mainfrom
Anurag-S1ngh:fix/2407-lazy-batch-reader
Open

Anurag-S1ngh wants to merge 1 commit into
apache:mainfrom
Anurag-S1ngh:fix/2407-lazy-batch-reader

Conversation

@Anurag-S1ngh

Copy link
Copy Markdown
Contributor

Rationale for this change

to_arrow_batch_reader() is documented as the low-memory way to stream scan results, one RecordBatch at a time. In practice it sent every file scan task to the executor and materialized each task's batches into a list, so consuming one batch could read every file in the scan. Delete files were also read for all tasks up front.

This adds ArrowScan.to_record_batches_lazy() and uses it from to_arrow_batch_reader(). The lazy path reads one task at a time in the calling thread, reads that task's delete files only when reached, and yields batches directly. to_table() and to_pandas() keep the existing threaded eager path.

Closes #2407.

Are these changes tested?

Yes. Added a counting FileIO regression test proving that consuming the first batch opens only the first data file, plus a test that compares rows, ordering, and limit behavior between the lazy and eager paths.

  • pytest tests/io/test_pyarrow.py tests/table/test_init.py -m unit: 442 passed, 1 skipped
  • pytest tests/ -m unit --ignore=tests/integration: 4884 passed, 6 skipped
  • ruff check and ruff format --check pass
  • ty check reports nothing for the new methods; existing diagnostics are unchanged

Are there any user-facing changes?

to_arrow_batch_reader() now uses substantially less memory for large scans. It is sequential rather than parallel, so to_table() and to_pandas() remain the better choices when throughput matters more than bounded memory.

Add ArrowScan.to_record_batches_lazy and use it for to_arrow_batch_reader. Delete files are read per task only when reached, and tasks are no longer materialized through the executor. Closes apache#2407.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Possible memory leak with to_arrow_batch_reader()

1 participant