Repository navigation
[Data][Delta DSv2][9/11] Drop the V1 fallback from the Delta DataSourceV2 reader - #68408
Open
abhishekverma-ray wants to merge 1 commit into
Open
abhishekverma-ray wants to merge 1 commit into
abhishekverma-ray wants to merge 1 commit into
Conversation
This was referenced Nov 20, 2026
abhishekverma-ray
marked this pull request as ready for review
November 20, 2026 17:34
Contributor
There was a problem hiding this comment.
Code Review
This pull request removes the fallback to the V1 reader when using the Delta DataSourceV2 pipeline in Ray Data. Instead of falling back to V1 when encountering unsupported features or PyArrow scan options, the V2 reader now directly validates the table and options, raising appropriate errors (such as NotImplementedError or ValueError) for unsupported configurations. There are no review comments provided, so I have no feedback to offer.
abhishekverma-ray
force-pushed
the
abhishek/delta-dsv2-6d-no-v1-fallback
branch
from
November 23, 2026 10:15
331aaa5 to
f2b723a
Compare
abhishekverma-ray
force-pushed
the
abhishek/delta-dsv2-6d-no-v1-fallback
branch
from
November 23, 2026 10:26
f2b723a to
2585e9a
Compare
sampan-s-nayak
pushed a commit
that referenced
this pull request
Nov 23, 2026
…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]>
sampan-s-nayak
force-pushed
the
abhishek/delta-dsv2-6d-no-v1-fallback
branch
from
November 23, 2026 11:13
2585e9a to
2ae1b5b
Compare
abhishekverma-ray
force-pushed
the
abhishek/delta-dsv2-6d-no-v1-fallback
branch
from
November 23, 2026 14:41
2ae1b5b to
fd7a045
Compare
abhishekverma-ray
force-pushed
the
abhishek/delta-dsv2-6d-no-v1-fallback
branch
from
November 24, 2026 03:09
fd7a045 to
6f0aa60
Compare
abhishekverma-ray
force-pushed
the
abhishek/delta-dsv2-6d-no-v1-fallback
branch
from
November 24, 2026 05:57
6f0aa60 to
6f016e4
Compare
abhishekverma-ray
force-pushed
the
abhishek/delta-dsv2-6d-no-v1-fallback
branch
from
November 25, 2026 02:54
6f016e4 to
4cb63b3
Compare
abhishekverma-ray
force-pushed
the
abhishek/delta-dsv2-6d-no-v1-fallback
branch
from
November 26, 2026 03:34
4cb63b3 to
3270382
Compare
goutamvenkat-anyscale
pushed a commit
that referenced
this pull request
Nov 27, 2026
…(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]>
read_delta sent the tables and arguments the V2 reader couldn't handle to the V1 reader. Once V2 is the default, that keeps V1 alive and makes the reader depend on the arguments. V2 now handles each case itself: - Column mapping and deletion vectors: V2 raises the errors V1 raised. Both readers share the error texts. - Reader version 2 or the columnMapping feature with the mapping mode "none" store columns under their names, so V2 reads them. - Other reader features (such as variantType) and reader versions: NotImplementedError. - Binary partition columns: NotImplementedError. V1 returned the log's escaped text (b'\\u0061\\u0062' for b'ab'). - A table's own path column with include_paths: ValueError. V1 replaced the column with the file paths. - PyArrow scan options: filter= raises as in read_parquet, the options that only tuned V1's reading (batch_size, readahead, threads, ...) are ignored with a warning, and any other option raises. - A table that can't be inspected raises the error instead of falling back. use_delta_datasource_v2 = False still reads with V1. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Abhishek Verma <[email protected]>
goutamvenkat-anyscale
force-pushed
the
abhishek/delta-dsv2-6d-no-v1-fallback
branch
from
November 27, 2026 18:12
3270382 to
5fd70b5
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
read_deltasent the tables and arguments the DataSourceV2 reader couldn't handle to the V1 reader. Once #68286 makes V2 the default, that would keep V1 alive and make the reader depend on the arguments. This layer removes the fallback: V2 reads each case or raises a clear error.This PR is part of a GitHub stack, so its diff shows only this layer.
Before
delta_datasource_v2_unsupported_reason()returned a reason, andread_deltaread with V1 instead, for: PyArrow scan options, column mapping, deletion vectors, reader version 2, reader features other thantimestampNtz, binary partition columns, a table's ownpathcolumn withinclude_paths, and tables it couldn't inspect.After
check_delta_table_is_readable()andcheck_delta_scan_options()raise instead:delta.columnMapping.modenotnone)NotImplementedErrorRuntimeErrorcolumnMappingfeature with modenonedeltalake1.5variantType), unknown reader versionsdeltalakeNotImplementedErrorb'\\u0061\\u0062'forb'ab')NotImplementedErrorpathcolumn +include_paths=TrueValueErrorfilter=ValueErrorpointing toDataset.filter, as inread_parquetbatch_size,batch_readahead,fragment_readahead,use_threads,cache_metadata,memory_poolValueErrorWith the private
_use_delta_datasource_v2switch off (the default until #68286),read_deltastill reads with V1. The DataSourceV2 README describes the new behavior; #68286 documents it in theread_deltadocstring.flowchart LR subgraph IO["Subsystem: IO"] subgraph RA["Component: read_delta (read_api.py)"] R["check_delta_scan_options()"] --> O["open_delta_table()"] end subgraph D["Component: datasource_v2/formats/delta"] C["check_delta_table_is_readable():<br/>raises, no V1 fallback"] E["column_mapping_error(), deletion_vectors_error():<br/>shared with V1"] end O --> C C --> E end classDef changed fill:#c8e6c9,stroke:#2e7d32,color:#000 classDef removed fill:#ffcdd2,stroke:#c62828,color:#000 class R,C,E changedSubsystems
IO (
_internal/datasource_v2/formats/delta/,read_deltainread_api.py),DataContextdocstring.Not a duplicate
Part of the Delta DataSourceV2 stack; it addresses review feedback on #68282. No other open PR removes the Delta V1 fallback.
Testing
Ray nightly of Nov 18 with CI pins (pyarrow 23.0.1, pandas 2.3.3, deltalake 1.5.0):
test_check_delta_table_is_readable(replacestest_delta_datasource_v2_unsupported_reason): each case in the table above, on a stub table.test_check_delta_scan_options: ignored options pass;filterand other options raise.test_reads_with_pyarrow_scan_options_on_v2(wastest_falls_back_to_v1_with_pyarrow_scan_options): a read withbatch_size=uses V2.test_delta.py's column mapping and deletion vector tests run on both readers and get the same errors; V2's deletion vector message names its own check as the cause.pathcolumn gave the V1 results in the table above.pytest python/ray/data/tests/datasource/test_delta.py python/ray/data/tests/datasource/test_delta_v2.py: 136 passed, 1 skipped (the existing V2 skip).tests/unit/datasource_v2/andtests/unit/datasource/: 1739 passed (I skippedtest_text_datasource_v2.py, which needssnappy, not installed locally).test_delta.pyandtest_delta_v2.py, 138 passed, 1 skipped; unit 1740 passed.deltalakeandpyarrowinstalled) reports no errors in the changed files.AI assistance was used (Claude Code); every line has been reviewed by the submitter.
🤖 Generated with Claude Code