Skip to content

[Data][Delta DSv2] Read Delta Lake tables with v2 checkpoints through DataSourceV2 - #68197

Closed
abhishekverma-ray wants to merge 9 commits into
ray-project:masterfrom
abhishekverma-ray:datasources-v2/read-delta-v2-5-v2-checkpoint
Closed

abhishekverma-ray wants to merge 9 commits into
ray-project:masterfrom
abhishekverma-ray:datasources-v2/read-delta-v2-5-v2-checkpoint

Conversation

@abhishekverma-ray

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

Copy link
Copy Markdown
Contributor

Summary

The DataSourceV2 Delta reader now accepts the v2Checkpoint reader feature. Databricks turns it on for new tables by default, and until now neither Ray reader could read those tables.

Stacked on #67679. Review only the top two commits: 65376ee330 and 29d1c7ec7c (trims the test).

Before

  • The V2 reader treated v2Checkpoint as unsupported and fell back to V1.
  • V1's DeltaTable.to_pyarrow_dataset() refuses the table: DeltaProtocolError: The table has set these reader features: {'v2Checkpoint'} but these are not yet supported by the deltalake reader.
  • So read_delta failed on any table whose only extra reader feature is v2Checkpoint.

After

  • v2Checkpoint only changes how the log is stored: a checkpoint can list the data files in sidecar files.
  • deltalake replays checkpoints and sidecars when it builds the add actions, so the V2 reader's listing already sees every file. Partition values, sizes and log statistics come from the same add actions.
  • Such tables now read with the V2 reader, including log-statistics file skipping.
  • Tables that also need other unsupported features (deletion vectors, column mapping, ...) still fall back to V1 as before.
flowchart TD
    subgraph Before
        subgraph BS[Subsystem: IO]
            subgraph BC[Component: read_delta reader choice]
                B1[Table with readerFeatures v2Checkpoint] --> B2[V2 eligibility check: unsupported feature]
                B2 --> B3[V1 to_pyarrow_dataset: DeltaProtocolError]
            end
        end
    end
    subgraph After
        subgraph AS[Subsystem: IO]
            subgraph AC[Component: read_delta reader choice]
                A1[Table with readerFeatures v2Checkpoint] --> A2[V2 eligibility check: supported]
                A2 --> A3[DeltaFileIndexer: add actions from checkpoint + sidecars]
                A3 --> A4[DeltaScanner reads the files]
            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 B3 removed
    class A2 changed
    class A3,A4 added
Loading

Subsystems

IO (_internal/datasource_v2/formats/delta/delta_datasource_v2.py: _SUPPORTED_READER_FEATURES).

Testing

New test. test_reads_tables_with_v2_checkpoints reads a table whose first files are listed only in a v2 checkpoint sidecar, plus one file committed after the checkpoint. It checks that the read uses V2 and returns every row.

  • delta-rs can't write v2 checkpoints, so the test makes one from a delta-rs table: it turns the classic checkpoint into a v2 checkpoint (a top-level JSON file plus a Parquet sidecar) and deletes the commits it covers.
  • With the change reverted, the read falls back to V1, which raises DeltaProtocolError, so the test fails.

Unit test. A new case in test_delta_datasource_v2_unsupported_reason. With the change reverted, it gets an unsupported reason instead of None.

Checked against a Databricks-written table:

  • reader 3, readerFeatures=["v2Checkpoint"], a v2 checkpoint with one sidecar;
  • read through Unity Catalog credential vending, then again from a local copy with the checkpointed commits deleted;
  • V2 count, sum(id) and a filtered count matched Databricks, on deltalake 1.5.0 (the CI pin) and 1.6.6.
  • deltalake 1.5.0 doesn't return log statistics for files listed in a struct-only sidecar (delta.checkpoint.writeStatsAsJson=false). Those files are simply not skipped, and the filtered count is still correct.

Commands and results (deltalake 1.5.0, pyarrow 23.0.1):

  • pytest python/ray/data/tests/datasource/test_delta_v2.py: 69 passed
  • pytest python/ray/data/tests/unit/datasource_v2/ python/ray/data/tests/unit/datasource/: 1132 passed, 125 skipped
  • pytest python/ray/data/tests/datasource/test_delta.py: 63 passed, 1 skipped
  • pytest python/ray/data/tests/datasource/test_delta_v2.py -k v2_checkpoint on deltalake 1.6.6: 1 passed
  • The same test with v2Checkpoint removed from _SUPPORTED_READER_FEATURES: 1 failed (DeltaProtocolError)
  • pre-commit and pyrefly (CI settings) on the changed files: clean

Not a duplicate. No open PR touches Delta v2Checkpoint support (searched open PRs for "v2Checkpoint" and "delta v2 checkpoint"). The V2 Delta reader only exists in this stack.

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

🤖 Generated with Claude Code

@abhishekverma-ray
abhishekverma-ray requested review from a team as code owners November 16, 2026 06:54
@abhishekverma-ray abhishekverma-ray added data Ray Data-related issues go add ONLY when ready to merge, run all tests labels Nov 16, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request implements a new DataSourceV2 reader for Delta Lake tables (DeltaDatasourceV2), enabling Ray to read Delta tables using the V2 datasource pipeline. It introduces log-based file listing, partition pruning, and file skipping using transaction log statistics, with fallback to the V1 reader for unsupported features. The review feedback suggests adding an early return in partition_values_as_strings when the table is empty to prevent a potential KeyError when accessing partition columns.

Returns:
One mapping per ``add`` action, in the same order.
"""
columns = {}

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.

medium

If the Delta table is empty (has 0 files), the table returned by get_add_actions(flatten=True) might not contain the partition columns, which would cause a KeyError when attempting to access add_actions[ADD_ACTION_PARTITION_PREFIX + field.name]. Adding an early return when add_actions.num_rows == 0 avoids this potential error and improves efficiency.

    if add_actions.num_rows == 0:
        return []
    columns = {}

abhishekverma-ray and others added 8 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]>
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 (ray-project#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]>
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]>
Turn `DataContext.use_delta_datasource_v2` on by default, so
`read_delta` pins the table version when called, lists the data files
in Ray tasks, skips files using the log's statistics and reads row-group
read units. Tables the DataSourceV2 reader can't read yet still use the
V1 reader. Opt out with `RAY_DATA_USE_DELTA_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]>
Databricks turns on the v2Checkpoint reader feature for new tables by default. The V1 reader's to_pyarrow_dataset refuses such tables, and the V2 reader fell back to V1 because it didn't list the feature as supported, so neither reader could read them.

v2Checkpoint only changes how the log is stored: checkpoints can list the data files in sidecar files, which deltalake replays when it lists the add actions. The V2 reader now accepts the feature. A new test builds a table whose files are listed only in a v2 checkpoint's sidecar and reads it, with and without log-statistics pruning.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Abhishek Verma <[email protected]>
The filter cases covered log-statistics skipping, which this change
doesn't touch. Keep the one read that fails when v2Checkpoint isn't
allowed, and build the table with fewer rows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Abhishek Verma <[email protected]>
@abhishekverma-ray

Copy link
Copy Markdown
Contributor Author

Closing in favor of #68287. 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 #68287.

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