Skip to content

[Data][Delta DSv2][6/7] Support generated_id_column checkpointing for Delta reads - #67678

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

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

Conversation

@abhishekverma-ray

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

Copy link
Copy Markdown
Contributor

Summary

CheckpointConfig(generated_id_column=...) now works with read_delta on the DataSourceV2 path. Stacked on #67890 (independent of #67677).

Before

Generated IDs are Parquet-only; #67889 rejects them for read_delta.

After

A generated ID names a row's place in its Parquet data file (file, row group, row). Delta data files never change, so a job resumed against the same table version finds every ID again, and its listing skips finished files and row groups as for Parquet. read_delta without version= reads the version that is latest at call time, so a resumed job may read a newer one, and rows a commit in between rewrote into new files (compaction, overwrite) get new IDs and are processed again: binding the column warns once in that case and asks for version=. IDs use the table-relative data file path.

Subsystems

Logical planning (rules/bind_generated_id_column.py), IO (formats/delta/); messages and docs in planner.py, checkpoint/interfaces.py.

Testing

  • test_delta_v2.py: IDs name each row's file / row group / row; a rerun after success writes nothing; a job failed partway and resumed writes every row and deletes its checkpoint; read_delta records whether the version was pinned.
  • test_delta_datasource_v2.py: binding adds the column, warns only without version=.
  • Delta suites — 81 passed; tests/unit/datasource_v2/ — 824 passed; test_checkpoint.py — 97 passed (17 S3-fixture tests need the local moto server).
  • Removing the warning, warning when pinned, or dropping the pinned flag in the datasource or read_delta fails a test.

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

🤖 Generated with Claude Code

@abhishekverma-ray
abhishekverma-ray force-pushed the datasources-v2/read-delta-v2-3-checkpoint branch 3 times, most recently from 798be47 to d749b21 Compare November 5, 2026 11:22
@abhishekverma-ray
abhishekverma-ray force-pushed the datasources-v2/read-delta-v2-3-checkpoint branch from d749b21 to 65f9e6b Compare November 6, 2026 03:43
@abhishekverma-ray abhishekverma-ray changed the title [Data][Delta DSv2][3/4] Support generated_id_column checkpointing for Delta reads [Data][Delta DSv2][6/7] Support generated_id_column checkpointing for Delta reads Nov 6, 2026
@abhishekverma-ray
abhishekverma-ray force-pushed the datasources-v2/read-delta-v2-3-checkpoint branch 3 times, most recently from ce1b41b to f973034 Compare November 10, 2026 05:16
@abhishekverma-ray abhishekverma-ray added data Ray Data-related issues go add ONLY when ready to merge, run all tests labels Nov 10, 2026
@abhishekverma-ray
abhishekverma-ray marked this pull request as ready for review November 10, 2026 06:24
@abhishekverma-ray
abhishekverma-ray requested review from a team as code owners 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 the DeltaDatasourceV2 reader to support reading Delta Lake tables via the DataSourceV2 pipeline. It includes log-based file indexing, file pruning using transaction log statistics, and integration with the Parquet V2 scanner. Additionally, it enhances partition parsing to support null fallbacks (e.g., HIVE_DEFAULT_PARTITION) across multiple formats and fixes a pickling bug in ParquetFileReader. Feedback suggests using random.randint instead of time.time_ns() for more robust shuffle seeding, and extending the file pruning logic to support set literals in IN predicates.

Comment on lines +221 to +225
self._shuffle_config: Optional[FileShuffleConfig] = (
FileShuffleConfig(seed=time.time_ns() % _INT32_MAX)
if shuffle == "files"
else shuffle
)

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

Using time.time_ns() for seeding can lead to deterministic or colliding seeds in highly parallel environments if multiple datasets are initialized at the exact same nanosecond. It is more robust to use random.randint to generate the seed.

Suggested change
self._shuffle_config: Optional[FileShuffleConfig] = (
FileShuffleConfig(seed=time.time_ns() % _INT32_MAX)
if shuffle == "files"
else shuffle
)
import random
self._shuffle_config: Optional[FileShuffleConfig] = (
FileShuffleConfig(seed=random.randint(0, _INT32_MAX))
if shuffle == "files"
else shuffle
)

Comment on lines +125 to +130
if not (
isinstance(predicate.left, ColumnExpr)
and isinstance(predicate.right, LiteralExpr)
and isinstance(predicate.right.value, (list, tuple))
):
return None

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

The membership check for predicate.right.value currently only allows list and tuple. Supporting set as well would make the file pruning optimization more robust and prevent falling back to keeping all files when a set is used in is_in expressions.

Suggested change
if not (
isinstance(predicate.left, ColumnExpr)
and isinstance(predicate.right, LiteralExpr)
and isinstance(predicate.right.value, (list, tuple))
):
return None
if not (
isinstance(predicate.left, ColumnExpr)
and isinstance(predicate.right, LiteralExpr)
and isinstance(predicate.right.value, (list, tuple, set))
):

@abhishekverma-ray
abhishekverma-ray force-pushed the datasources-v2/read-delta-v2-3-checkpoint branch from f973034 to d680219 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.

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit d680219. Configure here.

@abhishekverma-ray
abhishekverma-ray force-pushed the datasources-v2/read-delta-v2-3-checkpoint branch 3 times, most recently from d8d7f1a to dd4ca87 Compare November 16, 2026 03:09
abhishekverma-ray and others added 5 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]>
@abhishekverma-ray

Copy link
Copy Markdown
Contributor Author

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

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