Skip to content

[Data] Read files of unknown size on DataSource V2 - #68397

Merged
sampan-s-nayak merged 3 commits into
masterfrom
abhishek/v2-unknown-file-sizes
Nov 23, 2026
Merged

sampan-s-nayak merged 3 commits into
masterfrom
abhishek/v2-unknown-file-sizes

Conversation

@abhishekverma-ray

@abhishekverma-ray abhishekverma-ray commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

DataSource V2 now reads files whose size the filesystem doesn't report, such as files on an HTTP server that sends no Content-Length. Before, V2 dropped them, and read_text sent every HTTP read to V1 to avoid that. Fixes #68381.

Before

After

  • Listing keeps a file of unknown size and stores its size as null in the manifest. Zero-size files are still skipped where they were before.
  • The manifest's size column is always int64, so a listing where every size is unknown doesn't get Arrow's null type.
  • Memory estimates for these files stay unknown (NaN):
    • RoundRobinPartitioner passes them as None, which WeightedRoundRobinPartitioner already spreads across buckets. Before, a NaN weight would have counted as 0 bytes and piled them into one task.
    • OnlineBinPacker gives each such whole file its own read task.
  • LineChunkFileIndexer reads such a file whole, since byte ranges need the size.
  • read_text no longer falls back to V1 for HTTP. It still does for arrow_open_stream_args ([Data] read_text on DataSource V2 should accept arrow_open_stream_args instead of falling back to V1 #68380).
  • The V2 text reader opens files with a streaming_read_buffer_size (32 MiB) buffer, as V1 does. Otherwise a file over 5 MiB on a server that sends its size but ignores range requests (such as python -m http.server) fails: fsspec reads in 5 MiB blocks, and the second block needs a range request.
  • Formats that read the end of a file (Parquet) can't read a non-seekable HTTP stream on V1 either. They now fail on V2 with the same error ("Cannot seek streaming HTTP file") instead of returning no rows.
flowchart TD
    subgraph Before
        subgraph BS[Subsystem: IO]
            subgraph BC[Component: DataSource V2 listing and partitioning]
                B1[list_file_infos] -->|size=None: skipped| B0[file dropped]
                B1 -->|size known| B2[FileManifest] --> B3[size estimator / partitioner]
            end
        end
    end
    subgraph After
        subgraph AS[Subsystem: IO]
            subgraph AC[Component: DataSource V2 listing and partitioning]
                A1[list_file_infos] -->|size known or None| A2[FileManifest: int64 size, null if unknown]
                A2 --> A3[estimator: NaN for unknown]
                A3 --> A4[RoundRobinPartitioner: spread unknowns across buckets]
                A2 --> A5[OnlineBinPacker: one task per unknown-size file]
                A2 --> A6[LineChunkFileIndexer: read unknown-size file whole]
            end
        end
    end
    classDef removed fill:#ffcdd2,stroke:#c62828,color:#000
    classDef added fill:#c8e6c9,stroke:#2e7d32,color:#000
    classDef changed fill:#fff9c4,stroke:#f9a825,color:#000
    class B0 removed
    class A1,A2,A3,A4,A5 changed
    class A6 added
Loading

Subsystems

IO (the behavior change, in _internal/datasource_v2/); API (read_text routing in read_api.py).

Testing

I extended or parametrized existing tests; there are no new test files. Each test fails when its part of the fix is reverted:

Test Change Fails on revert with
test_text.py::test_fsspec_http_file_system (V1/V2 × 1 or 2 paths × fsspec filesystem or auto-resolved × two test files). no-size: the server sends no Content-Length. no-ranges: a 6.4 MiB file the server sends whole, with its size, whatever range is asked for. Listing and sample keep the files; read_text HTTP routing removed; text reader buffer Whole fix reverted: the V2 cases fail the V2-route check (they go to V1). Listing fix reverted: ValueError: no files found. Buffer reverted: the 4 V2 no-ranges cases fail with "The HTTP server doesn't appear to support range requests"
test_online_bin_packer.py::test_whole_file_rows_pack_by_file_size (adds a row with an unknown size) Bin packer ValueError: cannot convert float NaN to integer
test_file_partitioners.py::test_round_robin_partitioner_with_no_size_estimates (adds the sampling estimator) Round robin, sampling estimator assert 1 == 2 (all files in one task), AssertionError in the estimator
test_line_chunking.py::test_indexer_keeps_a_file_that_fits_in_one_chunk_whole (adds an unknown size) Line chunker the old assert file_info.size is not None

test_read_text_routes_to_v1 loses its http case, since HTTP reads now go to V2.

Each module ran in its own pytest process, on macOS with Python 3.12, pyarrow 23.0.1 and fsspec 2023.12.1:

Command Result
pytest python/ray/data/tests/unit/datasource_v2 1365 passed, 225 skipped
pytest python/ray/data/tests/unit/datasource 126 passed
pytest python/ray/data/tests/datasource/test_text.py 29 passed, 1 skipped (after the buffer fix)
pytest python/ray/data/tests/datasource/test_read_parquet_v2.py 130 passed
pytest python/ray/data/tests/datasource/test_hive.py 36 passed
pytest python/ray/data/tests/datasource_v2 all passed (test_schema_worker_semantics.py run on its own)
pytest python/ray/data/tests/datasource/test_orc.py 217 passed, 6 failed

The 6 ORC failures come from my local setup, not this change. test_read_orc_v2_partitioned_scan_optimizations checks that the reader's file path ends in python/ray/data/..., but my environment loads Ray Data through a site-packages symlink. Every assertion before that one passes. The MCAP tests were skipped locally because the mcap library isn't installed. Pre-commit hooks pass, and pyrefly with CI's settings reports 0 errors on the changed files.

Not a duplicate: no open PR addresses #68381. The CSV port (#67904) lists it as a known gap.

This PR was written with AI assistance (Claude Code). I reviewed every changed line and ran the tests above.

🤖 Generated with Claude Code

V2 file listing dropped any file whose size the filesystem doesn't
report, such as a file on an HTTP server that sends no Content-Length.
A read of one such file failed with "no files found", and a read of
many silently left those files out. V1 reads them, so read_text sent
every HTTP read to V1.

Keep these files and carry their size as null in the file manifest:

- The shared listing, the text listing, the driver-side sample and the
  Parquet footer indexer no longer skip them. A format that needs to
  seek, like Parquet, now fails on them the same way V1 does instead
  of returning no rows.
- The manifest's size column is always int64, so an all-unknown
  listing doesn't get Arrow's null type.
- Memory estimates stay unknown (NaN). The round-robin partitioner
  spreads those files across buckets instead of counting them as
  zero bytes, and the bin packer gives each its own read task.
- The line chunker reads a file of unknown size whole.
- read_text no longer falls back to V1 for HTTP.

Fixes #68381

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Abhishek Verma <[email protected]>
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@abhishekverma-ray
abhishekverma-ray marked this pull request as ready for review November 20, 2026 06:41
@abhishekverma-ray
abhishekverma-ray requested review from a team as code owners November 20, 2026 06:41
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@abhishekverma-ray abhishekverma-ray added data Ray Data-related issues go add ONLY when ready to merge, run all tests labels Nov 20, 2026
construct_manifest typed sizes as List[Optional[int]]. List is
invariant, so callers passing a list[int] failed the pyrefly check.
Sequence is covariant and accepts both.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Abhishek Verma <[email protected]>

@rayo5o rayo5o 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.

Ran on head e35bed1 and merge base 32e5120 with the CI lock versions (pyarrow 25.0.1, fsspec 2023.12.1), and again with pyarrow 26.0.0: tests/unit/datasource_v2 1347 passed, 226 skipped on both pyarrow versions; test_text.py 21 passed, 1 skipped. The changed tests fail on the merge base and pass on head, same as your table.

I also read from a local HTTP server that leaves out Content-Length: read_text with 1, 4 and 200 files mixing known-size, unknown-size and empty files, plus one Parquet and one ORC file. Each run checked that the plan was ReadFiles. Row counts match V1 in every text case. Parquet and ORC fail with "Cannot seek streaming HTTP file" as you describe, and V1 fails on them too. The one difference from V1 I found is in the comment above.

return True
return not isinstance(filesystem, HTTPFileSystem)
return (
DataContext.get_current().use_datasource_v2 and arrow_open_stream_args is None

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.

With the HTTP check gone, a server that does send Content-Length but doesn't support range requests now fails on V2 for files over about 5 MiB. python -m http.server is one such server. read_text(url) with default settings:

File V1 V2 (this PR)
4 MB reads reads
6 MB reads ValueError: The HTTP server doesn't appear to support range requests...
30 MB reads same error
40 MB same error same error

The merge base sends all of these to V1 (I checked a 16 MB file there: it reads).

It comes from how the file is read, not the listing. TextReader._read_bytes calls f.readall(), and fsspec's HTTPFile reads ahead in 5 MiB blocks, so the second block needs a range request. V1 reads through a streaming_read_buffer_size buffer (32 MiB), which gets a file up to that size in one request. With fsspec directly, open_input_stream(url) on a 16 MB file fails with readall() and with 1 MiB reads, and works with 16 MiB reads, so reading in streaming_read_buffer_size chunks in _read_bytes would probably match V1. I didn't try that in the reader itself.

Files with no Content-Length, the case this PR is about, read fine on V2 at any size I tried, since fsspec opens them as a stream. The file in test_fsspec_http_file_system is about 15 KB, so the test can't hit this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks @rayo5o for checking this. Fixed in d60a07b: TextReader._read_bytes now opens files with buffer_size=streaming_read_buffer_size, as V1 does, so a server without range support returns files up to 32 MiB in one request. On python -m http.server, 6 MB and 30 MB files now read on V2, and a 40 MB file fails on both readers, same as V1.

test_fsspec_http_file_system now also reads a 6.4 MiB file from a test server that sends Content-Length and ignores range requests. Without the fix, its 4 V2 cases fail with "The HTTP server doesn't appear to support range requests".

…urce V2

With HTTP reads now on V2, a file over 5 MiB on a server that sends its
size but ignores range requests (such as python -m http.server) failed:
TextReader read the whole file through fsspec's 5 MiB blocks, and the
second block needs a range request. V1 opens files with a
streaming_read_buffer_size (32 MiB) buffer, which gets such a file in
one request. Open them the same way on V2.

The mock HTTP server gets a file larger than 5 MiB that it serves whole,
with its size, whatever range is asked for, and
test_fsspec_http_file_system reads it too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Abhishek Verma <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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] DataSource V2 silently skips files whose size is unknown (e.g. HTTP without Content-Length)

3 participants