Skip to content

[Data][Delta DSv2][10/11] Read Delta Lake tables through DataSourceV2 by default - #68286

Open
abhishekverma-ray wants to merge 16 commits into
abhishek/delta-dsv2-6d-no-v1-fallbackfrom
abhishek/delta-dsv2-7-flag-flip
Open

abhishekverma-ray wants to merge 16 commits into
abhishek/delta-dsv2-6d-no-v1-fallbackfrom
abhishek/delta-dsv2-7-flag-flip

Conversation

@abhishekverma-ray

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

Copy link
Copy Markdown
Contributor

Summary

Makes DataSourceV2 the default for read_delta. It deletes the temporary DataContext._use_delta_datasource_v2 switch from #68283, so read_delta follows use_datasource_v2 like read_parquet and read_orc, and that setting is on by default. Kept separate so it can be reverted alone.

Replaces #67679, 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 uses the V1 reader unless the private switch is set.

After

read_delta uses the DataSourceV2 reader:

  • the table opened once in a Ray task, with the version pinned at call time;
  • listing in Ray tasks;
  • files skipped using the log's statistics;
  • row-group read units;
  • generated-ID checkpointing.

It raises for tables it can't read yet (#68408). Because the table is opened and listed in Ray tasks, worker nodes need read access to the table's _delta_log, not only the driver; the read_delta docstring now says so. To read with V1, set DataContext.use_datasource_v2 = False or RAY_DATA_USE_DATASOURCE_V2=0. That shared setting also affects read_parquet and read_orc.

Subsystems

IO (DataContext, the read_delta and read_orc docstrings, the DataSourceV2 README).

Testing

pyenv with deltalake 1.5.0 and pyarrow 23. Counts are at the top of the stack (#68287):

  • test_delta.py, test_delta_v2.py and test_write_delta.py: 229 passed. test_delta.py switches readers with conftest's datasource_v2 fixture (use_datasource_v2). The new test_reads_with_v2_by_default checks that a fresh DataContext reads with V2.
  • tests/unit/datasource_v2/ and tests/unit/datasource/: 1588 passed.
  • test_catalog.py and test_write_delta_catalog_e2e.py: 47 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

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

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

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

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

@abhishekverma-ray abhishekverma-ray added data Ray Data-related issues go add ONLY when ready to merge, run all tests labels Nov 18, 2026
@abhishekverma-ray
abhishekverma-ray force-pushed the abhishek/delta-dsv2-7-flag-flip branch from 9fcd15d to 4ad5af6 Compare November 18, 2026 04:36
@abhishekverma-ray
abhishekverma-ray force-pushed the abhishek/delta-dsv2-7-flag-flip branch from 4ad5af6 to ee440c8 Compare November 19, 2026 03:48
@abhishekverma-ray
abhishekverma-ray force-pushed the abhishek/delta-dsv2-7-flag-flip branch from ee440c8 to 959c4e7 Compare November 19, 2026 04:23
@abhishekverma-ray
abhishekverma-ray removed this pull request from stack #68288 November 19, 2026 04:25
@abhishekverma-ray
abhishekverma-ray changed the base branch from abhishek/delta-dsv2-6-checkpoint to abhishek/delta-dsv2-6b-partition-filters November 19, 2026 04:25
@abhishekverma-ray abhishekverma-ray changed the title [Data][Delta DSv2][7/8] Read Delta Lake tables through DataSourceV2 by default [Data][Delta DSv2][8/9] Read Delta Lake tables through DataSourceV2 by default Nov 19, 2026
@abhishekverma-ray
abhishekverma-ray force-pushed the abhishek/delta-dsv2-7-flag-flip branch from 959c4e7 to fd576cb Compare November 19, 2026 04:49
@abhishekverma-ray
abhishekverma-ray force-pushed the abhishek/delta-dsv2-7-flag-flip branch from fd576cb to 37e3ff0 Compare November 20, 2026 17:28
@abhishekverma-ray
abhishekverma-ray removed this pull request from stack #68331 November 20, 2026 17:29
@abhishekverma-ray
abhishekverma-ray changed the base branch from abhishek/delta-dsv2-6b-partition-filters to abhishek/delta-dsv2-6d-no-v1-fallback November 20, 2026 17:29
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
sampan-s-nayak force-pushed the abhishek/delta-dsv2-7-flag-flip branch from 0bb3197 to e3e33fb Compare November 23, 2026 11:13
…r tests

- Make the opt-in switch private and temporary:
  `DataContext._use_delta_datasource_v2`, with no environment variable and no
  public docs. It keeps Delta on V1 while the rest of the stack lands, since
  `use_datasource_v2` is already on by default. The layer that makes V2 the
  default deletes it, so `use_datasource_v2` alone decides, as for the other
  formats. Error messages now point to `use_datasource_v2 = False`.
- List the data files in the order deltalake gives the add actions, not
  sorted by path. `to_pyarrow_dataset` uses the same order (newest commit
  first, unchanged by checkpoints on deltalake 1.5 and 1.6.6), so
  `preserve_order=True` returns rows in V1's order. New
  `test_preserve_order_matches_v1`; the listing unit test now checks the
  log's order. Both fail with the path sort.
- Trim test_delta_v2.py:
  - Drop tests that duplicate others: unknown columns, null partitions,
    the literal `__HIVE_DEFAULT_PARTITION__` string, and `shuffle="files"`.
  - Cut `test_filters_match_v1` to 8 predicates.
  - One case each for `columns=` and `include_paths`.
  - Fold the row-group listing check into
    `test_listing_skips_finished_row_groups`.
  - Drop the dead pyarrow < 15 skip (setup.py needs pyarrow 23 or newer).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Abhishek Verma <[email protected]>
@abhishekverma-ray
abhishekverma-ray force-pushed the abhishek/delta-dsv2-7-flag-flip branch from e3e33fb to bed5cc3 Compare November 23, 2026 14:41
…, shared test fixture

- The Delta listing skipped every file whose logged size was missing or 0.
  It now skips only empty files; a file of unknown size stays in, and its
  footer read finds the size.
- Only `DeltaWholeFileIndexer` (count()) uses the log's per-file row counts,
  so only it builds the path -> row count map.
- `read_delta` sends a read with `partition_filters` to the V1 reader before
  opening the table for the V2 checks.
- README: say what `DeltaScanner` changes from `ParquetScanner` and why the
  partition values come from the log.
- test_delta.py runs through conftest's `datasource_v2` fixture. Tests that
  take the V1 path with either reader (`partition_filters`, multiple paths,
  `_delta_file_sizes`) run once.
- The file-size test runs for both readers: a handler records
  `get_file_info` calls in a file, so calls in Ray tasks count too.
- Fix a test comment that credited `preserve_order` with the listing order.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Abhishek Verma <[email protected]>
abhishekverma-ray and others added 3 commits November 25, 2026 07:42
…ls out of repr

- DeltaTableSnapshot.add_actions sorts the add actions by path. deltalake
  lists them in the order of the latest checkpoint's rows, so one version
  could list its files in another order after a checkpoint is rewritten,
  which changes preserve_order reads and can mismatch a retried listing task.
- DeltaTableSnapshot leaves storage_options out of its repr.
- The absolute-path error no longer suggests the V1 reader, which fails on
  such tables too.
- read_delta logs when partition_filters send a read to the V1 reader; the
  README names that case.
- test_delta_v2.py runs under the datasource_v2 fixture with
  ray_start_regular_shared, checks the reader by the operator name in
  ds.stats(), and reads through Dataset only. The listing tests move to
  tests/datasource_v2/test_delta_footer_listing.py, which builds the indexer
  directly. test_delta_read_empty_table is split; the use_datasource_v2=False
  test moves to test_delta.py.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Abhishek Verma <[email protected]>
The DataSourceV2 Delta reader lists every data file of the pinned
version and reads every footer. Each `add` action in the log carries the
file's per-column minimum and maximum, so a file whose range proves no
row can match the read's predicate is now left out of the listing,
before its footer is read (#61547).

Skipping is conservative: anything unprovable keeps the file, and the
reader still applies the predicate to every row. Only bounds that are
exact for their type are used: string maximums can be truncated by the
writer, timestamp statistics are stored in milliseconds, and float
bounds may be NaN. Supports comparisons with a literal on either side,
IN, AND and OR.

Co-authored-by: tobby168 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Abhishek Verma <[email protected]>
deltalake writes decimal min/max statistics through float64. A decimal of
more than 15 digits comes back rounded, and one beyond the int64 range is
clamped to it, so the logged range can miss the file's real values and the
file was skipped although it held matching rows (a decimal(38, 0) equality
filter returned no rows). Use decimal statistics only when the column has
at most 15 digits, which float64 holds exactly.

Tests:
- The end-to-end pruning test compares with a filter applied to the
  materialized table instead of with the V1 reader, which skips files with
  the same statistics and so can't catch a wrong skip. Its table gains a
  decimal(38, 0) column beyond int64, which returned no rows before.
- A unit test pins the 15-digit boundary; the exact-type test drops its
  decimal case, now covered there.
- test_int_statistics keeps one literal-on-the-left case and one is_in case.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Abhishek Verma <[email protected]>
@abhishekverma-ray
abhishekverma-ray force-pushed the abhishek/delta-dsv2-7-flag-flip branch from 6733e00 to 51cfec0 Compare November 25, 2026 02:54
abhishekverma-ray and others added 8 commits November 26, 2026 08:57
… a 1 ms margin

Timestamp statistics were not used at all, because Spark and Databricks log
them cut to milliseconds: a file whose only row is at 12:00:00.000500 can be
logged with a maximum of 12:00:00.000, and trusting that maximum skips the
file for `ts > 12:00:00.000100`.

Use them again with each bound widened by 1 ms (the maximum up, the minimum
down), which makes them true bounds whichever way a writer cuts. The V1
reader (DeltaTable.to_pyarrow_dataset) also adds 1 ms to the maximum.
Time-filtered reads of event tables skip files again.

Tests: the unit test runs that case for timestamp and timestamp_ntz; it
fails both without the margin (the matching file is skipped) and with
timestamp statistics off (nothing is skipped). An end-to-end test rewrites a
real log's statistics to milliseconds and reads the 12:00:00.000500 row back;
it fails without the margin.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Abhishek Verma <[email protected]>
A generated ID names a row's place in its Parquet data file. Delta data
files never change, so the DataSourceV2 Delta reader, whose scanner is a
`ParquetScanner`, can produce them: a job resumed against the same table
version finds every ID again, and its listing skips the finished files
and row groups.

`read_delta` without `version=` reads the version that is latest when
the dataset is created, so a resumed job may read a newer one, and rows
a commit in between rewrote into new files (compaction, an overwrite)
get new IDs and are processed again. Binding the column warns once in
that case and asks for `version=`.

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

A generated ID names a row's data file. A job that reads the latest Delta
version and is resumed after a commit that rewrote files (OPTIMIZE, an
overwrite) found new files with new IDs and wrote their rows again, with only
a warning from the first run.

The Delta listing now checks the read units the checkpoint has as finished
against the version's data files. If any names a file the version doesn't
have, it raises InvalidCheckpointingConfig before reading, and says to pass
`version=` with the version the checkpointed run read. Appends between runs
remove no files, so their rows are read as new work, as before. The warning
for an unpinned read now names the version read (`DeltaScanner.version`), so
the user knows what to pass.

Why not stricter or looser:
- Requiring `version=` with generated_id_column would also block the common
  append-only case, where resuming the latest version is correct.
- Storing the version in the checkpoint and reusing it would need a new
  checkpoint metadata format; that can follow separately.

`_row_group_unit_file` maps a row group's read unit id back to its file.

Tests: `test_checkpoint.py`'s recovery and rerun-after-success tests are
parametrized over read_parquet and read_delta instead of copied. A Delta test
appends (rows read as new), compacts (the resume raises), then resumes at the
pinned version (nothing written again). The pinned-version scanner test is
replaced by one that checks the warning through read_delta.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Abhishek Verma <[email protected]>
read_delta sent reads that pass partition_filters to the V1 reader,
because the DataSourceV2 reader didn't apply them. Now the V2 listing
reads only the data files they select. deltalake selects them with
DeltaTable.file_uris, the same selection to_pyarrow_dataset makes for
the V1 reader, so both readers read the same files. The URIs are mapped
back to the log's paths through one prefix, checked against every file,
so a URI form the listing doesn't expect fails the read instead of
dropping files. read_delta checks the filters on the driver as for V1,
so invalid ones still fail when it's called.

test_delta.py's partition_filters tests now run through V2 for the v2
reader. Their file-list helper runs the V2 listing, which happens in a
Ray task when the read runs.

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

Checking that every URI deltalake returns is one prefix followed by a log
path built a second set of N joined strings. Look each URI's suffix up in the
set of log paths instead. Same result; the existing partition_filters tests,
including the one where the URIs don't match the log, cover it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Abhishek Verma <[email protected]>
read_delta opened the table on the driver for its version, schema and
the V2 check, and the listing task opened it again for the file list.
deltalake 1.6+ has no metadata-only load, so both loaded the whole log:
twice V1's requests to _delta_log, and the full file list on the driver.

Open the table once, in a Ray task, on every deltalake version. The
task returns the table's description (version, schema, partition
columns, V2 check) to the driver and keeps the add actions in the
object store, where the listing reads them. partition_filters are
checked and applied in the same task. The driver never holds the file
list, and the before/after-1.6 without_files split is gone.

The task also rejects a log that names data files by absolute path (a
shallow clone's), so read_delta fails instead of the listing task. The
V1 reader can't read such tables either, so the error no longer points
to it.

The add actions carry their version. If Ray rebuilt them by rerunning
the task, which may read a later version, or lost them, the listing
loads the pinned version itself. Errors from opening the table reach
the caller unwrapped. Reads with PyArrow scan options go to V1 without
the task.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Abhishek Verma <[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]>
Delete the temporary `DataContext._use_delta_datasource_v2` switch.
`read_delta` now follows `use_datasource_v2`, as `read_parquet` and
`read_orc` do, and that setting is on by default. So `read_delta` opens the
table once in a Ray task and pins its version, lists the data files there,
skips files using the log's statistics and reads row-group read units. It
raises for tables the DataSourceV2 reader can't read yet. To read with V1,
set `use_datasource_v2 = False` or `RAY_DATA_USE_DATASOURCE_V2=0`.

The flip is its own change so it can be reverted alone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Abhishek Verma <[email protected]>
@abhishekverma-ray
abhishekverma-ray force-pushed the abhishek/delta-dsv2-7-flag-flip branch from 51cfec0 to 6c47b75 Compare November 26, 2026 03:34
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]>

This branch has not been deployed

No deployments
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.

1 participant