Skip to content

[Data][Delta DSv2][4/7] Read Delta Lake tables through DataSourceV2 (opt-in) - #67890

Closed
abhishekverma-ray wants to merge 4 commits into
ray-project:masterfrom
abhishekverma-ray:datasources-v2/read-delta-v2-1d-read-delta
Closed

abhishekverma-ray wants to merge 4 commits into
ray-project:masterfrom
abhishekverma-ray:datasources-v2/read-delta-v2-1d-read-delta

Conversation

@abhishekverma-ray

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

Copy link
Copy Markdown
Contributor

Summary

Routes ray.data.read_delta through the Delta Lake DataSourceV2 reader behind DataContext.use_delta_datasource_v2 (env RAY_DATA_USE_DELTA_DATASOURCE_V2, default off). Last part of the split of #67676. Stacked on #67889; review only the top commit (a03167ace8). #67677 and #67678 build on it, and #67679 turns the flag on.

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 flag on (and use_datasource_v2, already the default), read_delta opens only the log (without_files=True) and reads through DeltaDatasourceV2 (#67889): 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. filesystem=, storage_options, catalog= and include_paths behave as before. Tables delta_datasource_v2_unsupported_reason() rejects keep using the V1 reader, with an info log saying why. So do reads that pass partition_filters (added in #67900): the V2 reader doesn't apply them yet and would read every partition, so V1 lists only the matching files. filter(expr) on partition columns already prunes in V2.

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(without_files=True)<br/>pin version, schema, partition cols"]
                A1 --> 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 added fill:#c8e6c9,stroke:#2e7d32,color:#000
    classDef changed fill:#fff9c4,stroke:#f9a825,color:#000
    class A0 changed
    class A1,A2,A3,A4 added
Loading

Subsystems

API (read_api.read_delta, DataContext.use_delta_datasource_v2) carries the change; IO for the README and 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:

  • pytest python/ray/data/tests/datasource/test_delta.py python/ray/data/tests/datasource/test_delta_v2.py: 111 passed, 1 skipped. Every test_delta.py test runs under both readers, including master's column-mapping and partition_filters tests; the skip is master's no-get_file_info listing check under V2, which lists in Ray tasks when the read runs (input_files() is empty before that on DSv2, as for read_parquet), so test_delta_file_indexer.py ([Data][Delta DSv2][2/7] List Delta Lake table files from the log #67888) checks V2's log sizes instead. test_partition_filters_fall_back_to_v1 fails without the fallback (the read goes to V2); test_delta_v2.py checks that 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=, plus count after overwrite, version pinning at call time, row-group splitting, resume, shuffle and each V1 fallback. 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, the string __HIVE_DEFAULT_PARTITION__ next to nulls) 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.
  • tests/unit/datasource_v2/: 958 passed; tests/unit/datasource/: 112 passed; test_write_delta.py: 105 passed (rebased onto master after [Data] Add partition_filters to read_delta and take file sizes from the log #67900).
  • Each guard (path decoding, log-based whole-file indexer, version pinning, projection pinning, the protocol fallback, shuffle, the indexer's own filesystem, schema pinning against tampered files) was removed one at a time and a test failed each time.
  • pre-commit, pyrefly (CI file set) and the API param coverage check pass.

AI assistance was used (Claude Code); every line has been reviewed by the submitter.

🤖 Generated with Claude Code

@abhishekverma-ray abhishekverma-ray added data Ray Data-related issues go add ONLY when ready to merge, run all tests labels Nov 6, 2026
@abhishekverma-ray abhishekverma-ray changed the title [Data][Delta DSv2][4/7] Read Delta Lake tables through DataSourceV2 behind a flag [Data][Delta DSv2][4/7] Read Delta Lake tables through DataSourceV2 (opt-in) Nov 6, 2026
@abhishekverma-ray
abhishekverma-ray force-pushed the datasources-v2/read-delta-v2-1d-read-delta branch from e77bdf3 to e4579ec Compare November 6, 2026 06:16
@abhishekverma-ray
abhishekverma-ray force-pushed the datasources-v2/read-delta-v2-1d-read-delta branch 2 times, most recently from 8c26073 to b08d237 Compare November 10, 2026 05:16
@abhishekverma-ray
abhishekverma-ray marked this pull request as ready for review November 10, 2026 06:24
@abhishekverma-ray
abhishekverma-ray requested a review from a team as a code owner November 10, 2026 06:24

@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 introduces a new DataSourceV2 implementation for Delta Lake tables, enabling Ray to read Delta tables using the newer V2 pipeline when use_delta_datasource_v2 is enabled. It adds log-based file indexing via DeltaFileIndexer and a dedicated DeltaScanner extending the Parquet scanner. Additionally, it enhances partition handling by introducing a null_fallback option to represent null partition values (e.g., __HIVE_DEFAULT_PARTITION__) with proper Arrow typing, refactors row-group bin packing and partitioning resolution, and fixes a pickling bug in ParquetFileReader by replacing an object sentinel with None. Comprehensive unit and integration tests have been added to validate these changes. No review comments were provided, so there is no feedback to address.

@abhishekverma-ray
abhishekverma-ray force-pushed the datasources-v2/read-delta-v2-1d-read-delta branch from b08d237 to e567b24 Compare November 11, 2026 05:25

@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.

richardliaw pushed a commit that referenced this pull request Nov 11, 2026
…he log (#67900)

## Summary

`read_delta` gains `partition_filters`, which lists and reads only the
matching partitions' files, and takes file sizes from the Delta log
instead of one `get_file_info` call per file.

## Before

`read_delta` had no way to read only some partitions:

- `DeltaTable.to_pyarrow_dataset()` was called without a filter, so the
dataset had a fragment for every file in the table.
- `ParquetDatasource.from_pyarrow_dataset` called `get_file_info` on
every fragment to size the read tasks: one request per file on object
storage, although the sizes are in the Delta log.
- A `filter` on a partition column became a PyArrow row filter, so every
file was still opened.

On a table with 26,085 files, a one-date read needs 60 of them; building
the dataset took 26,085 `get_file_info` requests before the read
started.

## After

- `read_delta(partition_filters=...)` takes deltalake's tuple filters:
`(column, op, value)` with `=`, `!=`, `<`, `<=`, `>`, `>=`, `in`, `not
in`. A flat list is an AND, and a list of lists is an OR of ANDs. Only
the matching partitions' files become fragments, so only they are sized
and read.
- deltalake 1.6.6 takes the filters as `file_pruning_predicate` (AND or
OR of ANDs). Older versions take them as `partitions`, which only
supports an AND list (deltalake 1.5.0 and 1.6.3 fail on an OR with `not
enough values to unpack`), so an OR of groups raises a clear error
asking for 1.6.6 there.
- Every column must be a partition column. deltalake would accept others
but prune them only by file statistics, so rows outside the filter would
come back. Use `Dataset.filter` for those.
  - `read_unity_catalog` passes it through `reader_kwargs`.
- File sizes come from the log's add actions. Their paths are
URL-encoded once more than the fragment paths (`p=a%2520b` vs
`p=a%20b`), so they're decoded once.
`ParquetDatasource.from_pyarrow_dataset` takes them as
`known_file_sizes` and calls `get_file_info` only for paths missing from
it.

```mermaid
flowchart TD
    subgraph Before
        subgraph BS[Subsystem: IO]
            subgraph BC["Component: read_delta → ParquetDatasource.from_pyarrow_dataset"]
                B1["DeltaTable.to_pyarrow_dataset()<br/>every file"] --> B2["get_file_info per fragment"]
                B2 --> B3["read tasks: every file"]
            end
        end
    end
    subgraph After
        subgraph AS[Subsystem: IO]
            subgraph AC["Component: read_delta → ParquetDatasource.from_pyarrow_dataset"]
                A0["partition_filters<br/>(validated: partition columns only)"] --> A1["to_pyarrow_dataset(file_pruning_predicate | partitions)<br/>matching files only"]
                A1 --> A2["sizes from the Delta log<br/>(get_file_info only for misses)"]
                A2 --> A3["read tasks: matching files"]
            end
        end
    end
    classDef added fill:#c8e6c9,stroke:#2e7d32,color:#000
    classDef changed fill:#fff9c4,stroke:#f9a825,color:#000
    class A0 added
    class A1,A2 changed
```

## Subsystems

API (`read_api.read_delta`, new `partition_filters` parameter) carries
the change; IO for `ParquetDatasource.from_pyarrow_dataset`'s
`known_file_sizes`.

## Not a duplicate

#62959 ("Add DeltaDatasource with partition predicate pushdown") was
closed by the stale bot in May 2026 without review. No open PR adds
partition filters to `read_delta`. The DataSourceV2 Delta reader in
review (#67888–#67890) prunes partitions from `filter(expr)`; it will
send reads with `partition_filters` to this reader until it supports
them natively.

## Testing

macOS / Python 3.12, env pinned to the CI lock (pyarrow 23.0.1,
deltalake 1.5.0):

- `pytest python/ray/data/tests/datasource/test_delta.py`: 31 passed on
deltalake 1.5.0, and 31 passed with deltalake 1.6.6 on the path. On a
table with two files per date partition, `Dataset.input_files()` lists
only the matching partitions' files, and the rows match, for:
  - `=`, `in`, a range, and an AND of two conditions;
- an OR of AND groups, which reads on 1.6.6 and raises the clear error
on 1.5.0;
- invalid filters (a data column, an empty list, a short tuple, an empty
group), which raise `ValueError`;
  - `read_unity_catalog(reader_kwargs={"partition_filters": ...})`.
- With a filesystem that counts `info` calls and partition values with
special characters (`a b`, `x/y`, `100%`), building the dataset makes 0
`get_file_info` lookups. With the log sizes disabled, it makes 4 (one
per file).
- `_delta_file_sizes` matches the real file sizes, keyed by the fragment
paths deltalake builds, special characters and null partitions included.
- `test_catalog.py`: 46 passed; `test_write_delta.py`: 101 passed;
`tests/unit/datasource/`: 94 passed.
- pre-commit, pyrefly (CI file set) and the API param coverage check
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: Claude Opus 5.5 <[email protected]>
@abhishekverma-ray
abhishekverma-ray force-pushed the datasources-v2/read-delta-v2-1d-read-delta branch 3 times, most recently from 3f9c011 to d6519cb Compare November 16, 2026 03:09
abhishekverma-ray and others added 4 commits November 16, 2026 12:26
Add the listing for the Delta Lake DataSourceV2 reader. A Delta table's
data files are the ones its transaction log names at a version, not
whatever the table directory holds, so the indexers here read the file
list from the log instead of walking directories:

- `DeltaTableSnapshot`: a picklable reference to one table version. A
  `deltalake.DeltaTable` can't be pickled, so listing tasks reopen the
  table from it at the version the driver pinned.
- `DeltaFileIndexer(_DeltaLogListing, FooterFileIndexer)`: lists the
  `add` actions, then reads each file's Parquet footer, so listing rows
  are row-group runs (pruning, read units and resume 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 once. Partition
  values come from Hive-style directories, parsed with
  `null_fallback=HIVE_DEFAULT_PARTITION`; a file not under them, or a
  partition value that is literally `__HIVE_DEFAULT_PARTITION__`, fails
  the listing instead of reading wrong values.
- The indexer carries the table's filesystem and the read's shuffle,
  since the framework passes neither to a metadata-backed source.

Nothing uses the indexers yet: the datasource and `read_delta` wiring
follow in separate PRs.

Co-authored-by: tobby168 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Abhishek Verma <[email protected]>
The listing took each file's partition values from its Hive directory and
dropped the ones the log records, so it failed tables the V1 reader reads:
files outside partition directories (the Delta protocol doesn't require
them) and the string `__HIVE_DEFAULT_PARTITION__`, which shares a directory
with null values.

Now the listing reads the values from the `add` actions:
- `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` evaluates the pushed-down partition predicate on
  those values.
- Both indexers add them to each manifest in `PARTITION_VALUES_COLUMN`,
  which the bin packer carries to the read tasks.
  The reader that uses it comes with the datasource.

The two directory checks go. Also drop the unused
`list_files_from_file_infos` override and `DeltaWholeFileIndexer`'s
`shuffle_config`, and the unit tests that the `read_delta` tests cover.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Abhishek Verma <[email protected]>
Add `DeltaDatasourceV2`, a `DataSourceWithMetadata` for one version of a
Delta Lake table, and `DeltaScanner`:

- The driver opens the log without its file list, pins the version and
  takes the schema and partition columns from the log; listing goes
  through the `DeltaFileIndexer` from the previous PR.
- Data files are Parquet: `DeltaScanner` is a `ParquetScanner`, so the
  filter, column and limit pushdown are inherited. Partition columns keep
  their place in the output, and an `include_paths` `path` column comes
  last, as with the V1 reader.
- Partition values come from the log, not from the paths:
  `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.
  `ParquetScanner` gets a `reader_class` attribute for that.
- Everything is read through a filesystem rooted at the table directory,
  as `DeltaTable.to_pyarrow_dataset` does: the caller's, or a
  `deltalake` `DeltaStorageHandler` built from `storage_options`.
- `delta_datasource_v2_unsupported_reason` says why 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`.
- `generated_id_column` rejects Delta reads for now.
- The pickle gate scan allowlists `delta_datasource_v2.py`, whose only
  match is a schema `.to_arrow()`; data files are read and gated in
  `ParquetFileReader`.

`read_delta` doesn't use the datasource yet; that wiring follows in a
separate PR.

Co-authored-by: tobby168 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Abhishek Verma <[email protected]>
Route `read_delta` through `DeltaDatasourceV2` when the new
`DataContext.use_delta_datasource_v2` (env
`RAY_DATA_USE_DELTA_DATASOURCE_V2`, default off) and `use_datasource_v2`
are both set. The driver then opens only the log (`without_files=True`),
and tables `delta_datasource_v2_unsupported_reason` rejects keep using
the V1 reader, with an info log saying why. Reads that pass
`partition_filters` also use the V1 reader: the V2 reader doesn't apply
them yet, so it would read every partition.

Every `test_delta.py` test now runs under both readers (except the V1
listing's no-`get_file_info` check: V2 lists in Ray tasks, and
`test_delta_file_indexer.py` covers its log sizes), and
`test_delta_v2.py` checks that V2 returns the same rows and schema as V1
for partitioned tables, filters, `columns=`, `include_paths` and a
table-rooted `filesystem=`, plus count after overwrite, version pinning,
row-group read units, resume, shuffle and the V1 fallbacks. Tables
whose paths don't give their partition values (random file prefixes,
timestamp partitions with a time zone, the string
`__HIVE_DEFAULT_PARTITION__` next to nulls) read the same through V2,
with and without a filter on the partition column.

Co-authored-by: tobby168 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Abhishek Verma <[email protected]>
@abhishekverma-ray
abhishekverma-ray force-pushed the datasources-v2/read-delta-v2-1d-read-delta branch from d6519cb to a03167a Compare November 16, 2026 07:00

@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

Reviewed by Cursor Bugbot for commit a03167a. Configure here.

FileShuffleConfig(seed=time.time_ns() % _INT32_MAX)
if shuffle == "files"
else shuffle
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Limit applied before Delta row-group shuffle

Medium Severity

Delta applies FileShuffleConfig inside the indexer because _read_datasource_v2 gives metadata-backed sources no listing shuffle. ListFiles.shuffle_config_factory therefore stays None, so DeriveListFilesPushdown still pushes a limit into listing. Footer reads then stop at that limit and only afterward permute row-group runs, so small_chunks_shuffle with a pushed-down limit samples the first files by path instead of a shuffled pool of every run.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit a03167a. Configure here.

richardliaw pushed a commit that referenced this pull request Nov 17, 2026
)

## 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]>
@abhishekverma-ray

Copy link
Copy Markdown
Contributor Author

Closing in favor of #68283. Richard asked for the remaining Delta DSv2 PRs as a GitHub stack, so they now live on branches in ray-project/ray instead of my fork. The code is the same, rebased onto current master.

The stack is https://github.com/ray-project/ray/stack/68288, and each PR now shows only its own diff. Earlier review comments stay here for reference. Please leave new comments on #68283.

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]>
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