Skip to content

[Data][Delta DSv2][5/7] Skip Delta data files using the statistics in the log - #67677

Closed
abhishekverma-ray wants to merge 5 commits into
ray-project:masterfrom
abhishekverma-ray:datasources-v2/read-delta-v2-2-log-pruning
Closed

abhishekverma-ray wants to merge 5 commits into
ray-project:masterfrom
abhishekverma-ray:datasources-v2/read-delta-v2-2-log-pruning

Conversation

@abhishekverma-ray

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

Copy link
Copy Markdown
Contributor

Summary

The DataSourceV2 Delta reader now leaves out data files whose per-file statistics in the Delta log rule out the read's predicate, before their footers are read (#61547). Stacked on #67890.

Before

Every data file of the pinned version is listed and its footer read; only row groups are pruned, from the footers.

After

DeltaFileIndexer evaluates the pushed-down predicate against each add action's min.<col> / max.<col> and lists only the files that may match. Skipping is conservative: anything unprovable keeps the file, and the reader still filters every row. Only bounds that are exact for their type are used — string maximums can be truncated by writers, timestamp statistics are stored in milliseconds, and float bounds can be NaN — which the original pruning in #65142 didn't account for. Supports <, <=, >, >=, == (literal on either side), is_in, &, |.

flowchart LR
    A["add actions @ pinned version"] --> P["statistics_keep_mask(predicate)"]
    P --> F["footer reads (kept files only)"]
    F --> B["OnlineBinPacker"]
    classDef added fill:#c8e6c9,stroke:#2e7d32,color:#000
    class P added
Loading

Subsystems

IO (_internal/datasource_v2/formats/delta/).

Testing

  • test_delta_file_pruning.py — 53 passed, including a randomized check that a file with a matching row is never dropped.
  • test_delta_file_indexer.py — listing skips exactly the ruled-out files.
  • test_delta_v2.py — 13 predicates on a Z-ordered-style table (int, string, date, float) return the same rows as V1; full Delta suites 88 passed; tests/unit/datasource_v2/ 882 passed.
  • Removing each guard (string max, timestamps, NaN, unknown stats, OR with an unprovable side, literal-on-left flip, EQ bounds, the indexer's use of the predicate) fails a test.
  • pre-commit, pyrefly (the new module joins the pyarrow.compute exclusions), API param coverage pass.

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-2-log-pruning branch 2 times, most recently from 8041515 to ef475aa Compare November 2, 2026 16:19
@abhishekverma-ray
abhishekverma-ray force-pushed the datasources-v2/read-delta-v2-2-log-pruning branch from ef475aa to f3ad6b1 Compare November 5, 2026 11:22
@abhishekverma-ray
abhishekverma-ray force-pushed the datasources-v2/read-delta-v2-2-log-pruning branch from f3ad6b1 to 27d67fd Compare November 6, 2026 03:43
@abhishekverma-ray abhishekverma-ray changed the title [Data][Delta DSv2][2/4] Skip Delta data files using the statistics in the log [Data][Delta DSv2][5/7] Skip Delta data files using the statistics in the log Nov 6, 2026
@abhishekverma-ray
abhishekverma-ray force-pushed the datasources-v2/read-delta-v2-2-log-pruning branch 3 times, most recently from 4984a46 to 7f39f53 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 a new DeltaDatasourceV2 reader to route Delta Lake table reads through the DataSourceV2 pipeline, adding support for log-based file listing, statistics-based file pruning, and row-group level partitioning. The review feedback identifies a critical backward-compatibility issue with the use of pyarrow.nulls in file_based_datasource.py and partitioning.py. Since Ray Data supports PyArrow versions >= 12.0.0 and pa.nulls was introduced in 15.0.0, these calls should be replaced with pa.array to avoid runtime errors on older PyArrow installations.

if field in column_names
else _null_partition_type(field, field_types)
)
column = pa.nulls(len(table), null_type)

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.

high

Using pyarrow.nulls introduces a backward-compatibility issue because it was added in PyArrow 15.0.0. Ray Data supports older PyArrow versions (e.g., >= 12.0.0), where calling pa.nulls will raise an AttributeError. Please use pa.array([None] * len(table), type=null_type) instead, which is fully backward-compatible.

Suggested change
column = pa.nulls(len(table), null_type)
column = pa.array([None] * len(table), type=null_type)

Comment on lines +355 to +357
pa.nulls(
1, _null_partition_type(col, self._scheme.field_types)
)

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.

high

Using pyarrow.nulls introduces a backward-compatibility issue because it was added in PyArrow 15.0.0. Ray Data supports older PyArrow versions (e.g., >= 12.0.0), where calling pa.nulls will raise an AttributeError. Please use pa.array([None], type=...) instead, which is fully backward-compatible.

                            pa.array([None], type=_null_partition_type(col, self._scheme.field_types))

@abhishekverma-ray
abhishekverma-ray force-pushed the datasources-v2/read-delta-v2-2-log-pruning branch from 7f39f53 to 5bfcf6b 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.

@abhishekverma-ray
abhishekverma-ray force-pushed the datasources-v2/read-delta-v2-2-log-pruning branch 2 times, most recently from 1f43ab6 to d600f37 Compare November 12, 2026 04:27

@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 d600f37. Configure here.

abhishekverma-ray and others added 3 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]>
abhishekverma-ray and others added 2 commits November 16, 2026 12:26
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]>
@abhishekverma-ray

Copy link
Copy Markdown
Contributor Author

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

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