Skip to content

[Data](3/n) Read JSON and JSON Lines on DataSource V2, splitting large JSONL files - #67905

Merged
sampan-s-nayak merged 8 commits into
masterfrom
dsv2-json
Nov 23, 2026
Merged

sampan-s-nayak merged 8 commits into
masterfrom
dsv2-json

Conversation

@NightWing1998

@NightWing1998 NightWing1998 commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

read_json runs on DataSource V2 for both lines=False and lines=True when use_datasource_v2 is on (the default). Large uncompressed JSON Lines files are split into byte ranges read by separate tasks. lines=True parses with pandas, as V1 does, so it reads what V1 reads; lines=False parses with pyarrow.json, as V1 does. Where V2 falls back to V1 or behaves differently, see Gaps with V1.

Before

read_json always used V1, which reads each file whole in one task:

  • lines=False used ArrowJSONDatasource (pyarrow.json);
  • lines=True used PandasJSONDatasource (pandas.read_json, in frames sized from the target block size).

After

  • Routing. read_json builds JsonDatasourceV2 and goes through ListFiles -> ReadFiles. It falls back to V1 in the cases listed under Falls back to V1.
  • Which files split. With lines=True, every large uncompressed file. With lines=False, only .jsonl files, because a .json file may be one document, such as a top-level array. See Read whole, not split.
  • lines=True parsing. PandasJsonLinesFileReader parses each chunk's lines with pandas.read_json, through the function V1's PandasJSONDatasource now shares, and yields pandas blocks. Lines that pyarrow.json rejects still read: mixed-type columns, array lines, and nested values whose shape changes. Compressed and unknown-size files stream in frames instead of loading whole.
  • lines=False parsing. JsonFileReader parses each unit with pyarrow.json.read_json, as V1 does, and scans it as an in-memory fragment. A pyarrow.dataset JSON scan infers the schema from its first block and silently drops keys that first appear later; a test pins this. A chunk parses as one block, so no line can straddle two blocks. A whole file pyarrow rejects falls back to json.load with V1's warning and error messages.
  • Planning. With lines=False, the schema is inferred from a 1 MiB line-aligned prefix of each sampled file, so planning never reads a whole large file. If a prefix can't be parsed, such as a large top-level array, planning logs a warning and leaves that file's columns to the read task. A Snappy file isn't sampled, since pyarrow can't stream it and the driver would decompress all of it. The schema is only a sample, so a selected column it lacks is still read from the files and null-filled where a file lacks it. With lines=True the schema is unknown until a block is read, as in V1.
  • Newlines in values. The CSV PR's known limitation, a newline inside a quoted value, can't occur in JSON Lines: a JSON string can't hold a raw newline.
  • Unknown size. A file whose size the filesystem doesn't report, such as an HTTP file without Content-Length, is read whole as one stream. This is the CSV PR's change, shared through LineChunkableFileReader. read_json(lines=True) on V1 fails on such a file with "Cannot seek streaming HTTP file", so V2 reads a file V1 can't.
  • Compression names. A compression extension is matched ignoring case, and .br is read as brotli.
  • Snappy. JsonFileReader decompresses a Snappy file through the reader's own wrapped filesystem, not the fragment's plain one, so Hadoop framing applies on HDFS, as in V1.
flowchart TD
    subgraph Before
        subgraph B_API["API: read_api.read_json"]
            B0{"lines"} -->|False| B1["ArrowJSONDatasource (V1): whole file per task"]
            B0 -->|True| B2["PandasJSONDatasource (V1): whole file per task"]
        end
    end
    subgraph After
        subgraph A_API["API: read_api.read_json"]
            A0{"use_datasource_v2 and V2-supported args"}
        end
        subgraph A_IO["IO: datasource_v2"]
            A1["JsonDatasourceV2 (LineChunkableDatasourceV2)"] --> A2["LineChunkFileIndexer: lines=True all, lines=False .jsonl only"]
            A2 --> A3["RoundRobinPartitioner + OnDiskSizeEstimator"]
            A3 --> A4{"JsonScanner.lines"}
            A4 -->|False| A5["JsonFileReader: pyarrow.json.read_json -> in-memory fragment -> Arrow blocks"]
            A4 -->|True| A7["PandasJsonLinesFileReader: pandas.read_json per chunk or stream -> pandas blocks"]
            A5 -->|"whole file rejected"| A6["json.load fallback"]
        end
        A0 -->|yes| A1
        A0 -->|no| A8["V1 Arrow / pandas readers"]
    end
    classDef added fill:#c8e6c9,stroke:#2e7d32,color:#000
    classDef changed fill:#fff9c4,stroke:#f9a825,color:#000
    class A1,A2,A5,A7 added
    class A0,A6 changed
Loading

Gaps with V1

V2 reads JSON the same way V1 does in most cases. The cases below are where it doesn't: V1 still runs, V2 runs without splitting, or V2 runs and gives a different result. The CSV PR lists the gaps the two readers share; they're repeated here for read_json.

Falls back to V1

read_json builds the V1 Arrow or pandas datasource when any of these holds:

Condition Note
use_datasource_v2 is off DataContext.get_current().use_datasource_v2 = False, or RAY_DATA_USE_DATASOURCE_V2=0 before importing Ray.
arrow_open_stream_args is set For example {"compression": "gzip"}.
a JSON option other than read_options or parse_options is passed For example memory_pool.

lines=True still rejects filesystem, arrow_open_stream_args and JSON options with a ValueError, on both readers.

Read whole, not split

These files read on V2 but as one read task per file, as in V1:

  • lines=False and the file isn't .jsonl, because a .json file may be one document;
  • parse_options.newlines_in_values is set;
  • the file is compressed (gzip, snappy, and so on). With lines=True a compressed or unknown-size file streams in frames as in V1; with lines=False it is parsed whole;
  • the file's size is unknown, such as an HTTP file without Content-Length: it reads as one stream, and read-task sizing treats its size as unknown.

Behaves differently from V1

V1 V2
Dataset.input_files() The file paths. []: files are listed at execution, not planning. Parquet, ORC, Text and CSV on V2 do the same.
override_num_blocks=N on a small file The read task splits its output into N blocks (SplitBlocks(N)). N only sets how files and chunks are dealt to read tasks, so one small file is 1 block, for lines=True and lines=False. SetReadParallelismRule sets the split factor for V1 Read ops only, and plan_read_files_op has no equivalent.
LogicalPlan.initial_num_blocks() before execution A count. None, because listing runs at execution.
Operator and task names ReadJSON. ListFiles and ReadFilesJsonV2. Anything keyed on the names (stats output, metrics, tests) changes.
Schema before execution Not known. lines=False: known at planning, inferred from a 1 MiB line-aligned prefix of up to 16 sampled files, so it's a guess: a file whose prefix can't be parsed, or a Snappy file, adds no columns, and ds.columns() omits them. Selecting such a column still reads it. lines=True: not known, as in V1; ds.schema() runs the first read task.
A .jsonl file larger than the chunk size that holds one array Read whole; pyarrow rejects it and json.load reads it. Raises Failed to parse line-delimited JSON from file: a chunk can't fall back to json.load. A .jsonl file is JSON Lines by definition; the read_json note says so.
Column types across a split file A whole file is one task. lines=True frames type themselves independently. A split file's chunks type themselves independently, so a column can be int64 in one block and double in another. This is documented in the read_json note. lines=False can pin types with ParseOptions(explicit_schema=...).
Memory per read task lines=False (Arrow) reads each whole file into memory. lines=True (pandas) streams the file in frames sized from the target block size. lines=False: a split chunk, or a whole file that fits in one chunk, is read into memory and parsed as one block, so a task holds about the chunk's bytes times a parse factor. The CSV PR measured about 1.1 GiB per task at the default 128 MiB chunk (7-8 times the chunk) for CSV; I didn't measure JSON. lines=True: a task holds a chunk's bytes (up to 128 MiB) plus one pandas frame sized from the target block size; compressed and unknown-size files stream in frames of 10,000 rows as V1 does. Not measured. Tune with RAY_DATA_LINE_CHUNK_BYTES.

Data flow

How one read_json moves through planning, listing and reading. JSON keys name themselves, so listing reads nothing and every chunk parses on its own.

sequenceDiagram
    autonumber
    participant D as Driver (read_json)
    participant L as ListFiles task<br/>LineChunkFileIndexer
    participant P as RoundRobinPartitioner
    participant R as ReadFiles task<br/>JsonFileReader or PandasJsonLinesFileReader
    participant S as Storage (S3 or local)
    participant O as Downstream operators

    Note over D,S: Planning, on the driver
    D->>S: list until 16 files
    alt lines=False
        loop each sampled file
            D->>S: read its whole lines up to 1 MiB
            alt the prefix parses
                D->>D: schema from the prefix
            else the prefix is not JSON Lines, such as a large top-level array
                D->>D: warn, no columns from this file
            end
        end
    else lines=True
        D->>D: no schema, unknown until a block is read
    end
    D->>D: schema = sampled keys + partition and path columns

    Note over L,S: Execution: listing, no IO beyond the listing itself
    L->>S: list every file with its size
    loop each file
        alt uncompressed, larger than chunk_size, and lines=True or a .jsonl file
            L->>L: one row per 128 MiB chunk (keys name themselves, no header needed)
        else otherwise
            L->>L: one whole-file row
        end
    end
    L->>P: manifest rows
    P->>R: buckets weighed by bytes on disk

    Note over R,S: Execution: reading, each unit in a scan thread, retried on failure
    loop each unit
        alt chunk i
            R->>S: one ranged read [start - 1, end + 64 KiB)
            S-->>R: whole lines (a line belongs to the chunk holding its first byte)
        else whole file
            R->>S: read it, or stream it when compressed or of unknown size
        end
        alt lines=True
            R->>R: pandas.read_json in frames of about the target block size
            R->>R: check partition keys against the file's own, add the rest and the path column
            R->>O: pandas blocks
        else lines=False
            R->>R: pyarrow.json.read_json as one block, or json.load when pyarrow rejects a whole file
            R->>R: scan with the table's own types and null-fill missing keys
            R->>R: check partition keys against the file's own, add the rest and the path column
            R->>O: Arrow blocks, types unified downstream
        end
    end
Loading

Subsystems

IO (behavior change: _internal/datasource_v2/; FileReader._on_disk_column_names lets a line-chunked reader read a projected column the plan schema lacks, shared with CSV), API (routing and the read_json note in read_api.py, plus the use_datasource_v2 docstring list in context.py), and Logical planning (Scanner.read_schema and ReadFiles.infer_schema may return None, so a V2 read can have no schema until a block is read). Mechanical edits: V1's json.load fallback and pandas parsing move to module functions in _internal/datasource/json_datasource.py, and FileReader gains _make_dataset and counts rows with len.

Security: the lines=True reader yields pandas blocks, never a pa.Table, so raise_on_pickle_object_columns doesn't apply. A frame holds values json decoded and nothing is unpickled. Converting a mixed-type frame to Arrow would produce Ray's pickled extension type, which that check rejects, so the reader keeps the frames as pandas. This exemption from .claude/rules/security.md is recorded in the reader's docstring and a test asserts mixed-type frames stay pandas.

Testing

  • pytest python/ray/data/tests/unit/datasource_v2 python/ray/data/tests/unit/datasource/test_pickle_gate_coverage.py: 1547 passed, 226 skipped. The test_json_datasource_v2.py unit tests cover:

    • which files split;
    • schema inference from a 1 MiB prefix, and the warning and empty schema when a prefix can't be parsed;
    • no planning-time read of a Snappy file;
    • a projected column the plan schema lacks (a key first seen after the sample, or a column of a large array file) read from the files;
    • a block over the largest size pyarrow reads raising a clear error;
    • a .jsonl file holding an array raising;
    • lines=True mixed-type frames staying pandas;
    • lines=True having no plan-time schema;
    • split files read exactly once;
    • a key first seen after the first block;
    • a line longer than block_size;
    • chunks of only blank lines;
    • the top-level array fallback;
    • the lines=True error message;
    • gzip, brotli (.br), upper-case extensions and snappy;
    • a compressed file streaming in frames of 10,000 rows;
    • pinning types with explicit_schema across chunks;
    • V1/V2 routing;
    • a file key that differs from its partition value raises, and a null path value matches only an all-null key (the CSV PR's shared check, lines=True and lines=False).
  • pytest python/ray/data/tests/datasource/test_json.py: 138 passed, 6 failed. The four test_json_roundtrip[*-2] params (V1 and V2) and both TestPandasJSONDatasource::test_read_stream_with_target_output_size_bytes params fail identically without this change in my environment.

    • The tests use the shared datasource_v2 fixture. Assertions that differed by reader are separate V1 and V2 tests (input_files(), where the invalid UTF-8 error is raised). Routing is tested through the logical plan: V2 for both lines values, V1 for arrow_open_stream_args, memory_pool or use_datasource_v2 off.
    • New: projecting a column the planning sample lacks through read_json, limit on both readers, and a test that lines=True and lines=False return the same rows for hive partitions, include_paths and projection.
    • The four pandas lines=True tests (test_jsonl_read_invalid_format_includes_path, test_jsonl_read_invalid_utf8_includes_path, test_jsonl_lists, test_jsonl_mixed_types) now run under V1 and V2 through the datasource_v2 fixture.
    • New V2 tests read mixed-type, array, key-changing-type and nested lines across 256-byte chunks; apply projection, limit and include_paths; stream a gzip file; and skip blank lines.
    • -k http_file_system: 10 passed. lines=False runs on V1 and V2 (fsspec or auto-resolved filesystem, 1 or 2 paths); lines=True runs on V2 only, because V1's pandas reader can't read the file.
  • A V1 and V2 comparison of 12 lines=True inputs (mixed types, array lines, date-like and timestamp strings, uint64, nested objects, ints with nulls, all-null and missing keys, mixed lists) gave the same schema and rows on both.

  • pytest python/ray/data/tests/test_partitioning.py -k read_json: 11 passed. The whole file has 46 failures that are identical without this change in my environment (113 passed).

  • Other suites run for the shared FileReader and ReadFiles edits: test_text.py (29 passed), test_orc.py (221 passed, 2 failed in test_orc_roundtrip[*-2]), test_csv.py (42 passed, 4 failed in test_csv_roundtrip[*-2]), test_read_parquet_v2.py (129 passed, 1 failed: test_read_parquet_v2_retries_transient_filesystem_errors), test_read_files_logical.py (20 passed) and test_projection_fusion.py (112 passed, 19 failed). The Parquet retry test and the 19 projection-fusion failures fail identically without this change. The CSV and ORC roundtrip failures raise the same numpy.ndarray error as the JSON roundtrip; I didn't rerun them without this change.

  • pytest --doctest-modules -p ray.data.tests.doctest_pytest_plugin python/ray/data/read_api.py -k read_json: the lines=True example prints string in my environment, which has pandas 3.x, and the docstring keeps master's <class 'object'>, the pandas 2.x output. I didn't run it with pandas 2.x.

  • Performance, one 902 MiB JSONL file (17.8M rows of {"id", "score", "name"}) on local disk, ray.init(num_cpus=10), read_json(...).aggregate(Count, Sum, Min, Max) of id, 3 runs per row in a fresh process (the first run includes cluster warmup). The results were identical on every row (count 17,800,000).

    Read Parser Read tasks Min Median
    V1, lines=True pandas 1 16.3 s 17.6 s
    V2, lines=True pandas 8 10.4 s 11.1 s
    V1, lines=False pyarrow 1 6.4 s 7.3 s
    V2, lines=False pyarrow 8 2.5 s 2.8 s
    V1, lines=True, same data pre-split into 8 files pandas 8 10.3 s 11.8 s
    V2, lines=True, same 8 files pandas 8 10.3 s 10.3 s

    V2 splitting makes lines=True 1.6x faster and lines=False 2.6x faster. The pandas parse scales poorly across 8 tasks on this machine: V1 reading the data as 8 files takes as long as V2 splitting one file, so the splitting adds no overhead of its own. ds.stats() showed 43.7 s of total remote CPU time across the 8 V2 read tasks; I didn't find out why pandas scales worse than pyarrow here. The peak memory I sampled (drop in MemAvailable) was 0.4 to 1.6 GiB for V1 lines=True and 1.8 to 4.1 GiB for V2 lines=True; the V2 figure is 8 concurrent tasks. That sampling is noisy and includes page cache and the object store. Not measured: remote storage such as S3, other file sizes or row shapes.

  • pre-commit run on the changed files: clean.

Notes

  • Not a duplicate: no open PR or issue migrates read_json to DSv2.
  • Written with AI assistance (Claude Code).

🤖 Generated with Claude Code

@NightWing1998
NightWing1998 removed this pull request from stack #67906 November 6, 2026 13:59
@NightWing1998
NightWing1998 marked this pull request as ready for review November 11, 2026 16:51
@NightWing1998
NightWing1998 requested a review from a team as a code owner November 11, 2026 16:51

@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 implements the DataSourceV2 pipeline for JSON and JSON Lines files, introducing JsonDatasourceV2, JsonScanner, and JsonFileReader to support parallel reading of split uncompressed JSON Lines files. Feedback on the changes includes addressing a potential TypeError when a single JSON object is parsed by wrapping it in a list before calling pa.Table.from_pylist. Additionally, it is recommended to avoid using copy.deepcopy on PyArrow's ReadOptions objects, as this can fail depending on the PyArrow version, and instead instantiate new options objects directly.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 07a9557. Configure here.

sampan-s-nayak pushed a commit that referenced this pull request Nov 23, 2026
## 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
- V2 listing (`NonSamplingFileIndexer.list_file_infos`, which every V2
file indexer builds on) skipped any file with `size=None` and logged
"Skipping zero-size file". The text indexer, the driver-side sample and
the Parquet footer indexer skipped them too.
  - One such file: the read failed with "no files found".
  - Several: the files without a size were left out with no error.
- The code that groups files into read tasks assumed a real size.
`SamplingInMemorySizeEstimator` asserted sizes `>= 0`, `OnlineBinPacker`
called `int(file_size)`, and `LineChunkFileIndexer` asserted the size
wasn't `None`.
- `read_text` used V1 for any HTTP path or filesystem. CSV (#67904),
JSON (#67905) and WebDataset (#68017) have no such fallback, so they
would have silently skipped these files.

## 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` (#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.

```mermaid
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
```

## 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](https://claude.com/claude-code)

---------

Signed-off-by: Abhishek Verma <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
@NightWing1998
NightWing1998 requested review from a team as code owners November 23, 2026 09:15
@NightWing1998
NightWing1998 force-pushed the dsv2-json branch 3 times, most recently from 33afa5e to d2ceb04 Compare November 23, 2026 14:19
@NightWing1998
NightWing1998 force-pushed the dsv2-json branch 2 times, most recently from c31110b to d3e7940 Compare November 23, 2026 16:00
@NightWing1998 NightWing1998 added the go add ONLY when ready to merge, run all tests label Nov 23, 2026
Base automatically changed from dsv2-csv to master November 23, 2026 16:21

@abhishekverma-ray abhishekverma-ray 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, all 4 fixes check out on my side. Approving.

Could you file follow-up issues for:

  • Per-piece types: with lines=False, a column can be int64 in some blocks and double in others.
  • HTTP servers without range requests: on V2, a lines=False file over ~5 MiB fails (V1 reads it). This is the same gap as #68381.

NightWing1998 and others added 8 commits November 23, 2026 22:11
…no schema

No behavior change. `FileReader._make_dataset` builds the dataset of a
manifest, `_on_disk_column_names` decides which requested columns pyarrow
reads, `LineChunkableFileReader._read_chunk_lines` fetches a chunk's whole
lines, and the read loop counts rows with `len`, so a reader may yield
DataFrames. A scanner's `read_schema` may be `None`, and a requested column
the sampled plan schema lacks is read from the files and null-filled where
absent, not dropped as synthesized.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Signed-off-by: Dhruvil Shah <[email protected]>
No behavior change. `iter_json_lines_frames` is a module-level function so
another reader can parse JSON Lines with pandas, and `read_with_python_json`
is a plain function returning the table, or `None` for an empty buffer.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Signed-off-by: Dhruvil Shah <[email protected]>
…NL files

`read_json` routes to DataSource V2 unless it is given arguments only V1
supports. An uncompressed `.jsonl` file over `RAY_DATA_LINE_CHUNK_BYTES` is
read in byte-range chunks, one task per bin.

- `lines=False` parses with `pyarrow.json`, with V1's `json.load` fallback
  for a whole file, and types each chunk on its own. The plan schema is a
  1 MiB sample of up to 16 files, and a column it lacks is still read.
  Snappy files are not sampled, to keep them off the driver.
- `lines=True` parses with `pandas.read_json` and yields pandas blocks, as V1
  does, so mixed-type columns, arrays and nested values of changing shape
  still read. Compressed and unknown-size files stream in frames. The plan
  has no schema until a block is read.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Signed-off-by: Dhruvil Shah <[email protected]>
…rt reads

`_read_json_sample` took one `read(1 MiB + 1)` as the sample. A stream with
no `Content-Length`, such as an HTTP body, can return fewer bytes than
asked, so the sample was taken for the whole file and parsed cut mid-line.
Read until the sample is full or the stream ends.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Signed-off-by: Dhruvil Shah <[email protected]>
With `lines=True`, a block whose lines had none of a selected key dropped
that column, so blocks of one read had different columns and a function
reading the column failed on some of them. Add each requested column that a
block lacks as nulls, as V1 does.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Signed-off-by: Dhruvil Shah <[email protected]>
A `.json` file holding one array larger than the 1 MiB sample never parses,
so `ds.schema()` had no columns before execution while V1 shows the real
ones, and every such file logged a warning. Return no plan schema when the
sample found no file column, so a block is read to get it, as `lines=True`
does, and log the unparsable sample at debug level.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Signed-off-by: Dhruvil Shah <[email protected]>
`infer_schema()` can return None, so narrow it before reading `names`, and
mark the short-read test filesystem's `_open` override.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Signed-off-by: Dhruvil Shah <[email protected]>
@NightWing1998

Copy link
Copy Markdown
Contributor Author

Thanks, all 4 fixes check out on my side. Approving.

Could you file follow-up issues for:

per piece type is planned under another ticket - DATA-3839. For HTTP range requests, next PR in stack #68484 is addressing it.

@sampan-s-nayak
sampan-s-nayak enabled stacked auto-merge (squash) November 23, 2026 17:01
@sampan-s-nayak
sampan-s-nayak merged commit 678d06b into master Nov 23, 2026
5 checks passed
@sampan-s-nayak
sampan-s-nayak deleted the dsv2-json branch November 23, 2026 17:35
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.

3 participants