Repository navigation
[Data][Delta DSv2][1/4] Read Delta Lake tables through DataSourceV2 (opt-in) - #67676
abhishekverma-ray wants to merge 5 commits into
Conversation
`read_delta` builds the whole file list on the driver with `DeltaTable.to_pyarrow_dataset()` and reads it through the V1 `ParquetDatasource`. Add a DataSourceV2 reader for it, behind `DataContext.use_delta_datasource_v2` (env `RAY_DATA_USE_DELTA_DATASOURCE_V2`, default off): - `DeltaDatasourceV2` is a `DataSourceWithMetadata`. The driver opens the log without its file list, pins the version and takes the schema and partition columns from the log. - `DeltaFileIndexer` reopens the table at that version in the listing task and lists the `add` actions, then reads the files' footers as `FooterFileIndexer` does: listing rows are row-group runs, bin-packed with `OnlineBinPacker` and skipped on resume like Parquet's. Its `as_whole_file_indexer()` lists from the log too, for `count()`. - `DeltaScanner` is a `ParquetScanner`. Partition values come from the Hive partition directories; `Partitioning` gains `null_fallback` so `__HIVE_DEFAULT_PARTITION__` parses as null. - Data is read through the same table-rooted filesystem V1 uses, with paths relative to the table, so `filesystem=`, `storage_options` and `include_paths` behave as before. - Tables V2 can't read yet (deletion vectors, column mapping, randomized file prefixes) and reads with PyArrow scan options stay on the V1 reader, which fails or succeeds for them exactly as before. - `generated_id_column` isn't supported for `read_delta` yet. Co-authored-by: tobby168 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Abhishek Verma <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request introduces a new DataSourceV2 implementation for Delta Lake tables (DeltaDatasourceV2), enabling listing tasks to run in parallel on Ray tasks rather than on the driver, and splitting files into row-group read units. It also adds support for null fallbacks in Hive partitioning and integrates the new reader into ray.data.read_delta under a feature flag. Feedback on the changes suggests allowing synthesized columns (such as "path") in the requested columns list to avoid validation errors, and optimizing partition directory checks by comparing lengths instead of creating sets for every file.
| found = set(parser(path)) | ||
| except ValueError: | ||
| found = set() | ||
| if found != set(partition_columns): |
There was a problem hiding this comment.
Calling set(partition_columns) inside _check_partition_directories for every single file is inefficient because it creates a new set object found is guaranteed to be a subset of partition_columns (as the parser only extracts the specified partition columns), we can simply compare their lengths to verify that all partition directories are present.
| if found != set(partition_columns): | |
| if len(found) != len(partition_columns): |
There was a problem hiding this comment.
The expected set is now built once per listing. I kept the set comparison instead of comparing lengths, so a parser that returned a different key couldn't pass the check.
- Fall back to the V1 reader for tables partitioned by a timestamp with a time zone: Delta writes those partition directories in UTC without an offset, which doesn't cast to the column type. - Fail the listing when a string partition holds the literal `__HIVE_DEFAULT_PARTITION__`: Delta writes it to the same directory as null values, so reading partition values from directories would turn it into a null. - Accept `path` in `columns` with `include_paths`, and keep it last, as the V1 reader does. - Build the expected partition-column set once per listing. - Tests: move the empty-table checks into the shared `test_delta.py` test; round-trip the scanner and read with the reader created from it. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Abhishek Verma <[email protected]>
`ParquetFileReader` marked "no sampled batch size yet" with a module-level `object()` sentinel. A reader pickled before its first read unpickles a different object, so the identity check failed and the reader passed the sentinel to pyarrow as the batch size (`TypeError: an integer is required`). Use `None`, as `OrcFileReader` already does. Read tasks build their reader from the shipped scanner today, so no read path hits this yet. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Abhishek Verma <[email protected]>
`test_pickle_gate_coverage` flags `delta_datasource_v2.py` for `table.schema().to_arrow()`, which converts the Delta log's schema to an Arrow schema and reads no data. Data files are read and gated in `ParquetFileReader`. Add a test that a data file swapped for one with a pickled-object column doesn't run its pickle with either reader: both read data files with the log's schema, so the column comes back as plain bytes. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Abhishek Verma <[email protected]>
sampan-s-nayak
left a comment
There was a problem hiding this comment.
did one pass (yet to read the tests), mostly nits
| ) | ||
| metadata = table.metadata() | ||
| configuration = metadata.configuration or {} | ||
| if configuration.get("delta.columnMapping.mode", "none") != "none": |
There was a problem hiding this comment.
nit "
| if configuration.get("delta.columnMapping.mode", "none") != "none": | |
| if configuration.get("delta.columnMapping.mode", None): |
There was a problem hiding this comment.
Tables can set the mode to "none" explicitly. That string counts as true, so this check would wrongly send those tables to V1.
|
|
||
| def add_actions(self) -> pa.Table: | ||
| """The ``add`` actions of the pinned version, one row per data file.""" | ||
| # ``deltalake`` returns an arro3 table; ``pa.table`` converts it through |
There was a problem hiding this comment.
nit: typo
| # ``deltalake`` returns an arro3 table; ``pa.table`` converts it through | |
| # ``deltalake`` returns an arrow table; ``pa.table`` converts it through |
There was a problem hiding this comment.
“arro3”: not a typo. deltalake 1.x returns an arro3-core table, not a PyArrow one, which is why pa.table() converts it. I reworded the comment to make that clear.
| class DeltaScanner(ParquetScanner): | ||
| """Scanner for a Delta Lake table. | ||
|
|
||
| A Delta table's data files are Parquet files, so everything is inherited |
There was a problem hiding this comment.
does delta store all metadata in parquet files footer? is there no additional metadata in its logs which can use used for more optimised read? also wondering why we are reading the delta table this way instead of using a lib dedicated for reading delta tables which should in theory be the most optimal way to read the table?
There was a problem hiding this comment.
Good question! We already use deltalake for the Delta-specific part: it reads the log (table version, schema, list of data files). The data files themselves are plain Parquet, so Ray's Parquet reader reads them.
deltalake’s read functions read the whole table in one process, so to spread a read across Ray tasks we take the file list from it and read the Parquet files ourselves. V1 already does this too.
The log's extra data comes in follow-ups: per-file stats skip files in #67677, partition values from the log come after #67037, and row counts are planned for count().
|
As a note I have only reviewed how the changes in this PR affect Parquet reads. |
| #: HIVE partition value that stands for a null value, such as | ||
| #: ``HIVE_DEFAULT_PARTITION``. Path values equal to it parse as ``None``. | ||
| #: Specify `None` to keep every path value as written. | ||
| null_fallback: Optional[str] = None |
There was a problem hiding this comment.
read_parquet ignores null_fallback unless field_names is set. Is this deliberate?
There was a problem hiding this comment.
Good catch, not deliberate. When field_names isn’t set, the V2 Parquet and ORC readers rebuild the Partitioning from the path and dropped null_fallback. They now copy it with dataclasses.replace, so every field carries over. Added a read_parquet/read_orc test with and without field_names. Delta always sets field_names, so its reads weren’t affected.
Keep `Partitioning.null_fallback` when the Parquet and ORC V2 readers discover partition field names from the path: `resolve_partitioning` rebuilt the `Partitioning` field by field and left it out, so `read_parquet`/`read_orc` read `__HIVE_DEFAULT_PARTITION__` back as a string unless `field_names` was set. It now uses `dataclasses.replace`. Delta reader cleanups: - Rename `datasource_v2_unsupported_reason` to `delta_datasource_v2_unsupported_reason`. - Give separate fallback reasons for an unsupported reader version and for unsupported reader features, naming only the unsupported ones. - Say that `randomizeFilePrefixes` tables write files under random prefixes, not that they're unpartitioned. - Read the table URI from the pinned snapshot instead of keeping a copy. - Clarify comments and the literal-null-partition error message. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Abhishek Verma <[email protected]>
|
Closing in favor of a smaller stack, as reviewers asked. The code is the same as this PR's last revision; only the unit tests moved, with the listing tests now in their own file.
#67677, #67678 and #67679 will be rebased on #67890. The review threads here were addressed in round 2. The |
) ## Summary Adds the file listing for the Delta Lake DataSourceV2 reader: indexers that list a table version's data files from its transaction log. Second part of the split of #67676. Builds on #67887 (merged). Nothing uses the indexers until #67889 and #67890. The review changes are in the second commit (443b3a1cdb). ## Before No DataSourceV2 listing for Delta. `read_delta` lists files on the driver with `DeltaTable.to_pyarrow_dataset()`. ## After New `_internal/datasource_v2/formats/delta/delta_file_indexer.py`: - `DeltaTableSnapshot`: a picklable reference to one table version (`deltalake.DeltaTable` can't be pickled). Listing tasks reopen the table from it at the version the driver pinned. - `DeltaFileIndexer(_DeltaLogListing, FooterFileIndexer)`: lists the version's `add` actions instead of walking the directory, which also holds removed and uncommitted files, then reads each file's Parquet footer. Listing rows are row-group runs, so predicate pruning, read units and resume work as for Parquet. - `DeltaWholeFileIndexer`: the log-based listing for metadata-only reads. `FooterFileIndexer.as_whole_file_indexer` would walk the directory. - Paths are relative to the table root and URL-decoded exactly once; an absolute path fails with a pointer to the V1 reader. - Partition values come from the log's `add` actions, not from the paths: the Delta protocol doesn't require partition directories, and Delta stores a null and the string `__HIVE_DEFAULT_PARTITION__` in the same one. `partition_values_as_strings` casts them to the table's types and back to strings with Arrow, the form the reader casts back exactly, as it does a value parsed from a path. `DeltaPartitionPruner` prunes files on them, and both indexers add them to each manifest in `__delta_partition_values`, which `OnlineBinPacker` carries to the read tasks. The reader that uses it comes in #67889. - The indexer carries the table's filesystem and the read's shuffle, because the framework passes neither to a metadata-backed source. ```mermaid flowchart LR subgraph IO["Subsystem: IO"] subgraph D["Component: datasource_v2/formats/delta"] S["DeltaTableSnapshot<br/>(uri, pinned version)"] --> L["ListFiles task: _DeltaLogListing<br/>add actions → relative paths, sizes,<br/>partition values (pruned, added to manifests)"] L --> F["FooterFileIndexer<br/>footer reads → row-group runs"] L --> W["DeltaWholeFileIndexer<br/>one row per file"] end end classDef added fill:#c8e6c9,stroke:#2e7d32,color:#000 class S,L,F,W added ``` ## Subsystems IO (`_internal/datasource_v2/formats/delta/`). ## Not a duplicate Split out of #67676, which takes over #65142 (tobby168, credited as co-author) on the current DSv2 layout. No other open PR reads Delta through DSv2. ## Testing Same env as #67887: - `pytest python/ray/data/tests/unit/datasource_v2/test_delta_file_indexer.py`: 18 passed. Covers what `read_delta` can't reach: absolute paths, partition values from the log (a null and the literal `__HIVE_DEFAULT_PARTITION__` told apart, a file outside partition directories), their string round trip for each type, pruning on them, path pruners, log sizes and the manifest column. Listing through `read_delta` (pinned version, path decoding, shuffle, resume) is tested in #67890's `test_delta_v2.py`. - `pytest python/ray/data/tests/unit/datasource_v2/`: 933 passed; `tests/unit/datasource/` (pickle gate scan): 110 passed. - pre-commit and pyrefly (CI file set) pass. AI assistance was used (Claude Code); every line has been reviewed by the submitter. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Abhishek Verma <[email protected]> Co-authored-by: tobby168 <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
…68282) ## Summary Adds `DeltaDatasourceV2` and `DeltaScanner`, the DataSourceV2 datasource for one version of a Delta Lake table. Third part of the split of #67676. `read_delta` starts using it in #68283. Replaces #67889, which was opened from a fork; earlier review is there. This PR is part of a GitHub stack, so its diff shows only this layer. ## Before No DataSourceV2 datasource for Delta. ## After - `DeltaDatasourceV2(DataSourceWithMetadata)`: the driver pins the version and takes the schema and partition columns from the log. The file list is built from the log in a Ray task, not on the driver; deltalake 1.6 and later load it when the table is opened anyway (`without_files` is ignored there). `_get_file_indexer()` returns the `DeltaFileIndexer` from #67888, and `get_file_partitioner()` the shared row-group bin packer from #67887. #68407 opens the table only once, in a Ray task. - `DeltaScanner(ParquetScanner)`: data files are Parquet, so filter, column and limit pushdown are inherited. Partition columns keep their place in the output; an `include_paths` `path` column comes last, as with the V1 reader. - Partition values come from the log, not the paths (#67888): `DeltaScanner` prunes partitions with `DeltaPartitionPruner`, which the listing applies to each file's values, and reads with `DeltaFileReader`, a `ParquetFileReader` that takes each file's values from the manifest's `__delta_partition_values` column. `ParquetScanner` gets a `reader_class` class attribute so the scanner can swap the reader without copying `create_reader`. - Everything is read through a filesystem rooted at the table directory, as `DeltaTable.to_pyarrow_dataset` does: the caller's, or `deltalake`'s `DeltaStorageHandler` built from `storage_options`. Credentials and `az://` behave as in V1. - Data files are opened with their sizes from the log, so S3 gets no HEAD request per open: - With `deltalake`'s filesystem, `DeltaTableFileSystemHandler` wraps `DeltaStorageHandler`. The listing gives it every file's size before the footer reads, and `DeltaFileReader` gives it each manifest's sizes. It builds the deltalake handler on first use. - With a caller's `SubTreeFileSystem` over S3 (what `read_unity_catalog` passes), `filesystem_for_sized_opens` now unwraps it, as it already did a plain `S3FileSystem`. - `count()` takes each file's row count from the log (`numRecords`), not from its Parquet footer: the whole-file listing that `count()` uses carries the counts in a `__delta_num_records` manifest column, and `DeltaFileReader.read_metadata` reads a footer only for a file whose writer recorded no stats. Tables with deletion vectors, whose counts include deleted rows, never reach this reader. - `delta_datasource_v2_unsupported_reason()` says when a table must stay on the V1 reader: reader features beyond `timestampNtz` (deletion vectors, ...), column mapping, a partition column type whose values don't round-trip through a string (binary, ...), PyArrow scan options, or a table `path` column with `include_paths`. It fails closed. V1 reads some of these tables; it rejects the others (column mapping, deletion vectors) with the same error as before. #68408 replaces this fallback with errors, before #68286 makes V2 the default. - `generated_id_column` rejects Delta reads for now (#68285 adds support). - The pickle gate scan allowlists `delta_datasource_v2.py`: its only match is a schema `.to_arrow()`; data files are read and gated in `ParquetFileReader`. ```mermaid flowchart LR subgraph IO["Subsystem: IO"] subgraph D["Component: datasource_v2/formats/delta"] DS["driver: DeltaDatasourceV2<br/>log schema, pinned version"] --> IX["DeltaFileIndexer (2/11)"] DS --> BP["make_row_group_bin_packer (1/11)"] DS --> SC["DeltaScanner → DeltaFileReader<br/>partition values from the manifest,<br/>table-rooted filesystem"] end end classDef added fill:#c8e6c9,stroke:#2e7d32,color:#000 class DS,SC added ``` ## Subsystems IO (`_internal/datasource_v2/formats/delta/`; `ParquetScanner.reader_class`; `filesystem_for_sized_opens` in `_internal/util.py`). Ripple: logical planning (`bind_generated_id_column.py` rejects Delta scanners). ## Not a duplicate Split out of #67676, which takes over #65142 (tobby168, credited as co-author). No other open PR reads Delta through DSv2. ## Testing Same env as #67887: - `pytest python/ray/data/tests/unit/datasource_v2/test_delta_datasource_v2.py`: 20 passed. It covers: - the schema and partitioning from the log, and version pinning; - column order and `path` placement, and unknown-column errors; - pickling the indexer and scanner, and reading through the unpickled reader: each row gets its file's partition values from the log, and every data file opens with its size from the log (fails if the reader doesn't pass the sizes, or if two files' partition values are swapped); - `count()`'s row counts: from the log with no file opened, and from the footers when the log has no counts (with the reader change reverted, the first case opens all 3 files and fails); - every fallback reason, and a real table passing the eligibility check; - the `generated_id_column` rejection. - `pytest python/ray/data/tests/unit/datasource_v2/`: 1546 passed (rerun after the review round in a fresh env with the Nov 18 Ray nightly and CI pins). At the top of the stack (#68287), after the `count()` change: unit 1740 passed, `test_delta.py` and `test_delta_v2.py` 138 passed, 1 skipped. I skipped `test_text_datasource_v2.py`, which master added this week and which needs `snappy`, not installed locally. - `tests/unit/datasource/` (pickle gate scan): 125 passed. - `pytest python/ray/data/tests/test_util.py`: 51 passed, including `filesystem_for_sized_opens` on a `SubTreeFileSystem` over S3. - The S3 request count is tested end to end in #68283. - pre-commit and pyrefly (CI file set) pass. AI assistance was used (Claude Code); every line has been reviewed by the submitter. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Abhishek Verma <[email protected]> Co-authored-by: tobby168 <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
…(opt-in) (#68283) ## Summary Routes `ray.data.read_delta` through the Delta Lake DataSourceV2 reader behind the private, temporary `DataContext._use_delta_datasource_v2` (off by default). Last part of the split of #67676. #68284, #68285, #68330, #68407 and #68408 build on it. #68286 deletes the switch, so `use_datasource_v2` alone decides, as it does for `read_parquet` and `read_orc`. Replaces #67890, which was opened from a fork; earlier review is there. This PR is part of a GitHub stack, so its diff shows only this layer. ## Before `read_delta` opens the whole table on the driver (`DeltaTable.to_pyarrow_dataset()`), builds the full file list there, and reads it through the V1 `ParquetDatasource`, one read task per file. ## After With the switch on (and `use_datasource_v2`, already the default), `read_delta` reads through `DeltaDatasourceV2` (#68282): - The table on the driver is used only for its log metadata (`without_files=True` on deltalake before 1.6; later versions ignore it). - The file list is built in a Ray task from the log at the pinned version (#67888). - Files are split into row-group read units, and DSv2 pushdown and resume apply. - Files are listed in path order, so one version lists its files in one order however its log is checkpointed. `deltalake`'s own order follows the row layout of the latest checkpoint, which the protocol leaves to the writer. - `filesystem=`, `storage_options`, `catalog=` and `include_paths` behave as before. Some reads keep using the V1 reader, with an info log saying why: - Tables that `delta_datasource_v2_unsupported_reason()` rejects. V1 then reads the table that was checked, at the same version. On deltalake 1.6+ it reuses that table rather than loading it again; before 1.6 it reopens it with its file list. - Reads that pass `partition_filters` (added in #67900). The V2 reader doesn't apply them yet and would read every partition, so these reads go to V1 without opening the table for the V2 check, with their own info log. #68330 applies them in V2. `filter(expr)` on partition columns already prunes in V2. Later layers change this before #68286 makes V2 the default: - #68407 opens the table only once, in a Ray task, instead of on the driver and again in the listing. That task also rejects a log that names data files by absolute path (as a shallow clone's does), so `read_delta` fails right away. V1 can't read such tables either. - #68408 replaces the V1 fallback with errors. ### Changes from V1 - An empty table's `schema()` is the schema in the log. V1 returns `None`. - `input_files()` is empty until the read runs, because the files are listed in Ray tasks (as for `read_parquet` on DataSourceV2). - Read tasks hold row-group runs packed by size, not one file each. A large file can be split across tasks, and small files share one. - The log is read in Ray tasks (the listing here; from #68407 also the table open), so worker nodes, not only the driver, need read access to the table's `_delta_log`. Credentials in `storage_options` travel with the tasks. #68286 says so in the `read_delta` docstring. - A data file whose size is missing from the log is still read (its footer read finds the size); only files of size 0 are skipped. - With `preserve_order=True`, rows come back in path order. V1 reads files in `deltalake`'s order (newest commit first for JSON commits), which can change for one version when a checkpoint lays out its rows in another order. - Unchanged: the version is pinned when `read_delta` is called. ```mermaid flowchart TD subgraph Before subgraph BS[Subsystem: IO] subgraph BC["Component: read_delta (read_api.py)"] B1["driver: DeltaTable(...).to_pyarrow_dataset()<br/>(full file list)"] --> B2["V1 ParquetDatasource.from_pyarrow_dataset"] B2 --> B3["Read: one task per file"] end end end subgraph After subgraph AS[Subsystem: IO] subgraph AC["Component: read_delta → DataSourceV2 formats/delta"] A0{"_use_delta_datasource_v2, table supported<br/>and no partition_filters?"} -->|no| A5["V1 path (unchanged)"] A0 -->|yes| A1["driver: DeltaTable (log metadata)<br/>pin version, schema, partition cols"] A1 --> A2["ListFiles task: DeltaFileIndexer<br/>add actions at pinned version, sorted by path, footer reads"] A2 --> A3["OnlineBinPacker: row-group read units"] A3 --> A4["ReadFiles: DeltaScanner / ParquetFileReader"] end end end classDef added fill:#c8e6c9,stroke:#2e7d32,color:#000 classDef changed fill:#fff9c4,stroke:#f9a825,color:#000 class A0 changed class A1,A2,A3,A4 added ``` ## Subsystems API (`read_api.read_delta`, the private `DataContext._use_delta_datasource_v2`) carries the change; IO for the listing order, the README and the tests. ## Not a duplicate Split out of #67676, which takes over #65142 (tobby168, credited as co-author). richardliaw asked for a restart on the current DSv2 layout. No other open PR reads Delta through DSv2. ## Testing Same env as #67887 (deltalake 1.5.0, pyarrow 23). Each module runs in its own pytest process, as CI runs one `py_test` per file: - `test_delta.py`: 54 passed. `test_delta_v2.py`: 35 passed. `tests/datasource_v2/test_delta_footer_listing.py`: 2 passed. - `test_delta.py` runs under both readers through conftest's `datasource_v2` fixture. Tests that take the V1 path with either reader run once: the `partition_filters` tests (until #68330), the multiple-paths check, `_delta_file_sizes` and `use_datasource_v2 = False`. An empty table's schema from the log is a separate V2-only test. - The no-`get_file_info` check (`test_delta_read_takes_file_sizes_from_the_log`) runs under both readers. Its handler records each call in a file, so calls made inside Ray tasks count too. - What `test_delta_v2.py` checks, V2 only (`datasource_v2` fixture, `ray_start_regular_shared`), through `read_delta` and `Dataset` methods. It tells the readers apart by the read operator's name in `ds.stats()`. - V2 returns the same rows and schema as V1 for partitioned tables (special-character, null, int and date partitions). - Filters on partition and data columns, `columns=`, `include_paths` and a table-rooted `filesystem=`. - Count after overwrite, version pinning at call time, row-group splitting, the read order, a seeded shuffle, and each V1 fallback. - `test_delta_footer_listing.py` builds the indexer as `read_delta` does and lists the table: the row groups a resumed job skips, and those a filter prunes. Footer reads run in Ray actors, so these live in `tests/datasource_v2/`, not `tests/unit/`. - Tests that fail without this layer's fixes: - `test_a_version_reads_its_files_in_one_order` reads a table, rewrites its checkpoint with the rows in reverse order (as the protocol allows), and reads the same version again, through the same Dataset and a new `read_delta`. Without the path sort, the order changes; so does the listing-order check in `test_indexer_and_scanner_survive_worker_serialization`. - `test_snapshot_repr_leaves_out_storage_options` fails when `storage_options` is in the snapshot's `repr`. - `test_partition_filters_fall_back_to_v1` fails without the fallback (the read goes to V2). - `test_skips_only_empty_files` fails with the old size check, which also dropped files of unknown size. - `test_falls_back_to_v1_with_pyarrow_scan_options` appends to the table right after the check, with deltalake reporting 1.5 and 1.6. It checks that V1 reads the checked version and, on 1.6, opens the table once. Both cases fail with the old code, which reopened the latest version. - `test_partition_values_come_from_the_log` reads tables whose paths don't give their partition values: random file prefixes, timestamp partitions with a time zone, and the string `__HIVE_DEFAULT_PARTITION__` next to nulls. It reads them through V2 and matches V1, with and without a filter on the partition column. - `test_delta_read_does_not_unpickle_a_tampered_data_file`: a data file swapped for one with a pickled-object column reads as plain bytes under both readers, and its pickle never runs. The test also writes the swapped file's size into the log, because V2 opens data files with the log's sizes, as Delta readers do. - `test_s3_reads_send_no_head_requests` reads a table on moto S3, through deltalake's filesystem and through a caller's `SubTreeFileSystem` over S3. Using moto's request recorder, it checks that no data file gets a HEAD request. - `tests/unit/datasource_v2/` and `tests/unit/datasource/`: 1521 passed, 225 skipped. `test_write_delta.py`: 105 passed. - Each guard was removed one at a time, and a test failed each time: path decoding, the log-based whole-file indexer, version pinning, projection pinning, the protocol fallback, shuffle, the indexer's own filesystem, schema pinning against tampered files, the path order and the `repr`. - pre-commit and pyrefly (CI file set, with deltalake 1.5 and pyarrow 23 resolved) pass. AI assistance was used (Claude Code); every line has been reviewed by the submitter. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Abhishek Verma <[email protected]> Co-authored-by: tobby168 <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
Summary
Adds a DataSourceV2 reader for
ray.data.read_delta, behindDataContext.use_delta_datasource_v2(envRAY_DATA_USE_DELTA_DATASOURCE_V2, default off). It restarts #65142 on the current DSv2 layout, as discussed there.Before
read_deltaopens the whole table on the driver (DeltaTable.to_pyarrow_dataset()), builds the full file list there, and reads it through the V1ParquetDatasource, one read task per file.After
With the flag on (and
use_datasource_v2, already the default):DeltaDatasourceV2, aDataSourceWithMetadata).ListFilestask reopens the table at that version and lists theaddactions (DeltaFileIndexer). It extendsFooterFileIndexer, so listing rows are row-group runs:OnlineBinPackerpacks them into read tasks, row groups are pruned by the pushed-down predicate, and checkpoint resume skips finished ones, as for Parquet.DeltaScanner(aParquetScanner) and the Parquet reader, through the same table-rooted filesystem V1 uses, sofilesystem=,storage_options,catalog=andinclude_pathsbehave as before.Partitioninggains an opt-innull_fallbackso__HIVE_DEFAULT_PARTITION__parses as null; a file not under partition directories fails the read instead of returning nulls.to_pyarrow_datasetrejects, randomized file prefixes, PyArrow scan options in**arrow_parquet_args.generated_id_columnis rejected forread_deltauntil PR 3.flowchart TD subgraph Before subgraph BS[Subsystem: IO] subgraph BC["Component: read_delta (read_api.py)"] B1["driver: DeltaTable(...).to_pyarrow_dataset()<br/>(full file list)"] --> B2["V1 ParquetDatasource.from_pyarrow_dataset"] B2 --> B3["Read: one task per file"] end end end subgraph After subgraph AS[Subsystem: IO] subgraph AC["Component: DataSourceV2 formats/delta"] A1["driver: DeltaTable(without_files=True)<br/>pin version, schema, partition cols"] --> A2["ListFiles task: DeltaFileIndexer<br/>add actions at pinned version, footer reads"] A2 --> A3["OnlineBinPacker: row-group read units"] A3 --> A4["ReadFiles: DeltaScanner / ParquetFileReader"] 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 B1,B2,B3 removed class A1,A2,A3,A4 added(Before stays the path with the flag off and for tables V2 doesn't read.)
Subsystems
IO (
_internal/datasource_v2/formats/delta/,read_api.read_delta) carries the change. Ripple edits:datasource/partitioning.py(null_fallback),DataContext(flag),formats/parquet/parquet_datasource_v2.py(shared bin-packer factory, no behavior change),logical/rules/bind_generated_id_column.py(rejects Delta reads for now).Not a duplicate
Takes over #65142 (tobby168), which conflicts with the DSv2 reorg; @richardliaw asked for a restart on the current layout. tobby168 is credited as co-author. No other open PR reads Delta through DSv2.
Testing
macOS / Python 3.12, env pinned to the CI lock (deltalake 1.5.0, pyarrow 23.0.1, pandas 2.3.3, pytest 7.4.4):
pytest python/ray/data/tests/datasource/test_delta.py(every test under both readers) andtest_delta_v2.py— 73 passed. Rows and schema match V1 for partitioned tables (special-character, null, int and date partitions), filters on partition and data columns,columns=,include_paths, pinned versions, a table-rootedfilesystem=; plus count after overwrite, version pinned at call time, row-group splitting and resume skipping, shuffle, fallbacks.pytest python/ray/data/tests/unit/datasource_v2/— 820 passed.pytest python/ray/data/tests/test_partitioning.py— newnull_fallbacktests pass; the 12 S3-fixture tests need the moto server (not available locally).test_read_parquet_v2.py— 101 passed;test_write_delta.py— 101 passed.AI assistance was used (Claude Code); every line has been reviewed by the submitter.
🤖 Generated with Claude Code