Skip to content

[Data] Fix FileReader reading past a pushed-down row limit - #68343

Merged
sampan-s-nayak merged 4 commits into
ray-project:masterfrom
zzchun:fix/data-v2-limit-overread
Nov 24, 2026
Merged

sampan-s-nayak merged 4 commits into
ray-project:masterfrom
zzchun:fix/data-v2-limit-overread

Conversation

@zzchun

@zzchun zzchun commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Stop a DataSource V2 file reader as soon as it yields its pushed-down row budget. A zero-row budget skips Arrow dataset construction.

Before and after

Previously the reader pulled another batch before checking its budget. In an ordered two-file ORC read, both files were scanned even when the first batch satisfied the limit. The check now runs before the next pull. Errors still propagate from fragments needed to fill the budget, and parallel scans may already have prefetched data.

Subsystem

IO (DataSource V2 shared file reader).

flowchart LR
    subgraph Before["Before · IO / FileReader"]
        A1["Yield the final batch"] --> A2["Pull another batch"] --> A3["Check the budget and stop"]
    end
    subgraph After["After · IO / FileReader"]
        B1["Yield the final batch"] --> B2["Check the budget and stop"]
    end
    classDef removed fill:#ffcdd2,color:#222
    classDef added fill:#c8e6c9,color:#222
    class A2 removed
    class B2 added
Loading

Related work

Fixes #68341. #51966 tracks propagating limits into reads. #68338 and #68339 address surplus tasks after the downstream physical limit is satisfied. This change addresses the iterator inside a single read task after the limit has already reached the reader. The open-PR search found no change to this reader loop.

Testing

python -m pytest -q \
  python/ray/data/tests/unit/datasource_v2/test_file_reader.py \
  python/ray/data/tests/unit/datasource_v2/test_orc_file_reader.py \
  python/ray/data/tests/unit/datasource_v2/test_orc_datasource_v2.py

391 passed on 2c9d2b98b1 using the branch's Ray Data code with Python 3.12, PyArrow 26.0.1, and Ray Core nightly eb50407602.

Both shared-reader regression tests raise OSError with the PR base reader (3cba3775f0). On this branch, both pass.

  • limit=0 returns [] for a corrupt gzip file.
  • limit=1 returns the first row and the iterator finishes normally when a corrupt file follows a valid one, using the default execution settings.

@zzchun zzchun changed the title [Data] Stop file readers at a pushed-down row limit [Data] Fix FileReader reading past a pushed-down row limit Nov 19, 2026
@zzchun
zzchun marked this pull request as ready for review November 19, 2026 12:07
@zzchun
zzchun requested review from a team as code owners November 19, 2026 12:07

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request optimizes the file reader's limit handling by returning early when the limit is less than or equal to zero, and stopping file scanning as soon as the row limit is reached. It also adds unit tests to verify that scanning stops at the limit and that errors propagate correctly, and updates an existing test to use a predicate filter instead of a zero limit. There are no review comments, so I have no feedback to provide.

@ray-gardener ray-gardener Bot added data Ray Data-related issues community-contribution Contributed by the community labels Nov 19, 2026
@AarryaSaraf AarryaSaraf added the go add ONLY when ready to merge, run all tests label Nov 24, 2026

zzchun commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Hi @sampan-s-nayak, when you have a chance, would you mind reviewing this FileReader fix and merging it if it looks good to you? Thanks for your time!

@sampan-s-nayak sampan-s-nayak left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this!

@sampan-s-nayak
sampan-s-nayak merged commit b2d2fca into ray-project:master Nov 24, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community data Ray Data-related issues go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Data] FileReader requests another batch after reaching its row limit

3 participants