Repository navigation
[Data][Delta DSv2][5/7] Skip Delta data files using the statistics in the log - #67677
abhishekverma-ray wants to merge 5 commits into
Conversation
8041515 to
ef475aa
Compare
ef475aa to
f3ad6b1
Compare
f3ad6b1 to
27d67fd
Compare
4984a46 to
7f39f53
Compare
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
| column = pa.nulls(len(table), null_type) | |
| column = pa.array([None] * len(table), type=null_type) |
| pa.nulls( | ||
| 1, _null_partition_type(col, self._scheme.field_types) | ||
| ) |
There was a problem hiding this comment.
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))7f39f53 to
5bfcf6b
Compare
1f43ab6 to
d600f37
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit d600f37. Configure here.
d600f37 to
4ba14e2
Compare
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]>
4ba14e2 to
86dc6d2
Compare
|
Closing in favor of #68284. Richard asked for the remaining Delta DSv2 PRs as a GitHub stack, so they now live on branches in 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. |

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
DeltaFileIndexerevaluates the pushed-down predicate against eachaddaction'smin.<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 addedSubsystems
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.pyarrow.computeexclusions), API param coverage pass.AI assistance was used (Claude Code); every line has been reviewed by the submitter.
🤖 Generated with Claude Code