Repository navigation
[Data] Read files of unknown size on DataSource V2 - #68397
Conversation
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]>
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
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
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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]>
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, andread_textsent every HTTP read to V1 to avoid that. Fixes #68381.Before
NonSamplingFileIndexer.list_file_infos, which every V2 file indexer builds on) skipped any file withsize=Noneand logged "Skipping zero-size file". The text indexer, the driver-side sample and the Parquet footer indexer skipped them too.SamplingInMemorySizeEstimatorasserted sizes>= 0,OnlineBinPackercalledint(file_size), andLineChunkFileIndexerasserted the size wasn'tNone.read_textused V1 for any HTTP path or filesystem. CSV ([Data](2/n) Read CSV on DataSource V2, splitting large files across read tasks #67904), JSON ([Data](3/n) Read JSON and JSON Lines on DataSource V2, splitting large JSONL files #67905) and WebDataset ([Data] Migrate read_webdataset to DataSource V2 #68017) have no such fallback, so they would have silently skipped these files.After
int64, so a listing where every size is unknown doesn't get Arrow'snulltype.NaN):RoundRobinPartitionerpasses them asNone, whichWeightedRoundRobinPartitioneralready spreads across buckets. Before, aNaNweight would have counted as 0 bytes and piled them into one task.OnlineBinPackergives each such whole file its own read task.LineChunkFileIndexerreads such a file whole, since byte ranges need the size.read_textno longer falls back to V1 for HTTP. It still does forarrow_open_stream_args([Data] read_text on DataSource V2 should accept arrow_open_stream_args instead of falling back to V1 #68380).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 aspython -m http.server) fails: fsspec reads in 5 MiB blocks, and the second block needs a range request.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 addedSubsystems
IO (the behavior change, in
_internal/datasource_v2/); API (read_textrouting inread_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_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 noContent-Length.no-ranges: a 6.4 MiB file the server sends whole, with its size, whatever range is asked for.read_textHTTP routing removed; text reader bufferValueError: no files found. Buffer reverted: the 4 V2no-rangescases 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)ValueError: cannot convert float NaN to integertest_file_partitioners.py::test_round_robin_partitioner_with_no_size_estimates(adds the sampling estimator)assert 1 == 2(all files in one task),AssertionErrorin the estimatortest_line_chunking.py::test_indexer_keeps_a_file_that_fits_in_one_chunk_whole(adds an unknown size)assert file_info.size is not Nonetest_read_text_routes_to_v1loses itshttpcase, 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:
pytest python/ray/data/tests/unit/datasource_v2pytest python/ray/data/tests/unit/datasourcepytest python/ray/data/tests/datasource/test_text.pypytest python/ray/data/tests/datasource/test_read_parquet_v2.pypytest python/ray/data/tests/datasource/test_hive.pypytest python/ray/data/tests/datasource_v2test_schema_worker_semantics.pyrun on its own)pytest python/ray/data/tests/datasource/test_orc.pyThe 6 ORC failures come from my local setup, not this change.
test_read_orc_v2_partitioned_scan_optimizationschecks that the reader's file path ends inpython/ray/data/..., but my environment loads Ray Data through asite-packagessymlink. Every assertion before that one passes. The MCAP tests were skipped locally because themcaplibrary 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