Skip to content

[Data][Delta DSv2][3/11] Add the Delta Lake DataSourceV2 datasource - #68282

Merged
sampan-s-nayak merged 6 commits into
masterfrom
abhishek/delta-dsv2-3-datasource
Nov 23, 2026
Merged

sampan-s-nayak merged 6 commits into
masterfrom
abhishek/delta-dsv2-3-datasource

Conversation

@abhishekverma-ray

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

Copy link
Copy Markdown
Contributor

Summary

Adds DeltaDatasourceV2 and DeltaScanner, the DataSourceV2 datasource for one version of a Delta Lake table. Third part of the split of #67676. read_delta starts using it in #68283.

Replaces #67889, 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

No DataSourceV2 datasource for Delta.

After

  • DeltaDatasourceV2(DataSourceWithMetadata): the driver pins the version and takes the schema and partition columns from the log. The file list is built from the log in a Ray task, not on the driver; deltalake 1.6 and later load it when the table is opened anyway (without_files is ignored there). _get_file_indexer() returns the DeltaFileIndexer from [Data][Delta DSv2][2/7] List Delta Lake table files from the log #67888, and get_file_partitioner() the shared row-group bin packer from [Data][Delta DSv2][1/7] Shared Parquet and partitioning fixes for the Delta reader #67887. [Data][Delta DSv2][8/11] Open the Delta table once, in a Ray task #68407 opens the table only once, in a Ray task.
  • DeltaScanner(ParquetScanner): data files are Parquet, so filter, column and limit pushdown are inherited. Partition columns keep their place in the output; an include_paths path column comes last, as with the V1 reader.
  • Partition values come from the log, not the paths ([Data][Delta DSv2][2/7] List Delta Lake table files from the log #67888): 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's __delta_partition_values column. ParquetScanner gets a reader_class class attribute so the scanner can swap the reader without copying create_reader.
  • Everything is read through a filesystem rooted at the table directory, as DeltaTable.to_pyarrow_dataset does: the caller's, or deltalake's DeltaStorageHandler built from storage_options. Credentials and az:// behave as in V1.
  • Data files are opened with their sizes from the log, so S3 gets no HEAD request per open:
    • With deltalake's filesystem, DeltaTableFileSystemHandler wraps DeltaStorageHandler. The listing gives it every file's size before the footer reads, and DeltaFileReader gives it each manifest's sizes. It builds the deltalake handler on first use.
    • With a caller's SubTreeFileSystem over S3 (what read_unity_catalog passes), filesystem_for_sized_opens now unwraps it, as it already did a plain S3FileSystem.
  • count() takes each file's row count from the log (numRecords), not from its Parquet footer: the whole-file listing that count() uses carries the counts in a __delta_num_records manifest column, and DeltaFileReader.read_metadata reads a footer only for a file whose writer recorded no stats. Tables with deletion vectors, whose counts include deleted rows, never reach this reader.
  • delta_datasource_v2_unsupported_reason() says when 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. It fails closed. V1 reads some of these tables; it rejects the others (column mapping, deletion vectors) with the same error as before. [Data][Delta DSv2][9/11] Drop the V1 fallback from the Delta DataSourceV2 reader #68408 replaces this fallback with errors, before [Data][Delta DSv2][10/11] Read Delta Lake tables through DataSourceV2 by default #68286 makes V2 the default.
  • generated_id_column rejects Delta reads for now ([Data][Delta DSv2][6/11] Support generated_id_column checkpointing for Delta reads #68285 adds support).
  • The pickle gate scan allowlists delta_datasource_v2.py: its only match is a schema .to_arrow(); data files are read and gated in ParquetFileReader.
flowchart LR
    subgraph IO["Subsystem: IO"]
        subgraph D["Component: datasource_v2/formats/delta"]
            DS["driver: DeltaDatasourceV2<br/>log schema, pinned version"] --> IX["DeltaFileIndexer (2/11)"]
            DS --> BP["make_row_group_bin_packer (1/11)"]
            DS --> SC["DeltaScanner → DeltaFileReader<br/>partition values from the manifest,<br/>table-rooted filesystem"]
        end
    end
    classDef added fill:#c8e6c9,stroke:#2e7d32,color:#000
    class DS,SC added
Loading

Subsystems

IO (_internal/datasource_v2/formats/delta/; ParquetScanner.reader_class; filesystem_for_sized_opens in _internal/util.py). Ripple: logical planning (bind_generated_id_column.py rejects Delta scanners).

Not a duplicate

Split out of #67676, which takes over #65142 (tobby168, credited as co-author). No other open PR reads Delta through DSv2.

Testing

Same env as #67887:

  • pytest python/ray/data/tests/unit/datasource_v2/test_delta_datasource_v2.py: 20 passed. It covers:
    • the schema and partitioning from the log, and version pinning;
    • column order and path placement, and unknown-column errors;
    • pickling the indexer and scanner, and reading through the unpickled reader: each row gets its file's partition values from the log, and every data file opens with its size from the log (fails if the reader doesn't pass the sizes, or if two files' partition values are swapped);
    • count()'s row counts: from the log with no file opened, and from the footers when the log has no counts (with the reader change reverted, the first case opens all 3 files and fails);
    • every fallback reason, and a real table passing the eligibility check;
    • the generated_id_column rejection.
  • pytest python/ray/data/tests/unit/datasource_v2/: 1546 passed (rerun after the review round in a fresh env with the Nov 18 Ray nightly and CI pins). At the top of the stack ([Data][Delta DSv2][11/11] Read Delta Lake tables with v2 checkpoints through DataSourceV2 #68287), after the count() change: unit 1740 passed, test_delta.py and test_delta_v2.py 138 passed, 1 skipped. I skipped test_text_datasource_v2.py, which master added this week and which needs snappy, not installed locally.
  • tests/unit/datasource/ (pickle gate scan): 125 passed.
  • pytest python/ray/data/tests/test_util.py: 51 passed, including filesystem_for_sized_opens on a SubTreeFileSystem over S3.
  • The S3 request count is tested end to end in [Data][Delta DSv2][4/11] Read Delta Lake tables through DataSourceV2 (opt-in) #68283.
  • 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

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@abhishekverma-ray abhishekverma-ray added data Ray Data-related issues go add ONLY when ready to merge, run all tests labels Nov 18, 2026
@abhishekverma-ray

Copy link
Copy Markdown
Contributor Author

@AarryaSaraf , this addresses your review on #67889 (it moved here when the stack became a GitHub stack).

HEAD requests on S3: fixed. Data files now open with their sizes from the log, through deltalake's filesystem and through a caller's SubTreeFileSystem over S3. On moto, V2 now sends 0 HEAD requests per data file (it was 3). #68283 has a moto test for both filesystems.
without_files on deltalake 1.6+: docs fixed. read_delta passes it only before 1.6 (#68283).
Repeated tests: removed, and the supported case runs on a real table.
prune_input_split: removed.
Reader version 2: comment added, and the fallback reason names column mapping.
Shuffle seed: comment fixed. The thread explains why the seed is still drawn at creation.

The changes are in the top commit of this PR and of #68283.

_INT32_MAX = 2**31 - 1


def delta_datasource_v2_unsupported_reason(

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.

With V1 being deprecated, why fall back to it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

V1 isn't deprecated in the code yet: use_datasource_v2 = False is still the documented opt-out, and read_text falls back to V1 the same way. The fallback cases fall into two groups:

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.

Read_text has the wrong model in that case. If you mean we can temporarily add this Im fine with that but I dont see why we cant port the complete functionality within these 9 PRs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed. A silent fallback would keep V1 alive after the flag flip and make the reader depend on which arguments were passed. #68408, before the flip, removes it:

  • Tables V1 rejects too (column mapping, deletion vectors) now get the same error from V2. Unknown reader versions and other features (such as variantType) raise NotImplementedError. A table that can't be inspected raises the real error.
  • partition_filters already runs on V2 ([Data][Delta DSv2][7/11] Apply partition_filters in the Delta DataSourceV2 reader #68330).
  • Binary partition columns raise NotImplementedError. V1 doesn't really read them: it returns the log's escaped text (b'\\u0061\\u0062' for b'ab').
  • A table's own path column with include_paths=True raises ValueError. V1 silently replaced the column with the file paths.
  • PyArrow scan options: filter= raises, as in read_parquet. The options that only tuned V1's reading (batch_size, readahead, threads, ...) are ignored with a warning, and any other option raises instead of being dropped.


Args:
table: The table, opened at the version to read. Its file list
isn't needed: before deltalake 1.6, open it with

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.

On deltalake 1.6+ the driver loads every file's entry, with stats, only to read the version, schema, partition columns and protocol, and the listing task loads them again. Can the driver avoid opening the table?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not with deltalake as it is: 1.6 ignores without_files and skip_stats, and its Python API has no metadata-only load (delta-io/delta-rs#5034 asks for one). The driver needs the version, schema and protocol before any task runs. On 1.6+ that costs the driver the same as V1, which also loads the full table there; V2's second load is in the listing task.
Your comment did find a real double load: when V2 fell back, read_delta opened the table again for V1. Now V1 reads the table that was checked: on 1.6+ it reuses it, and before 1.6 it reopens it at the checked version (#68283). I left a note to switch once deltalake has a metadata-only load.

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.

On 1.6+ the driver loads the whole file list just for the version, schema and partition columns, and the listing task loads it again (count() on a 4-file table: 20 _delta_log requests on V2 vs 10 on V1). Could one Ray task open the table, return those to the driver, and keep the file list for the listing task?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in #68407. read_delta now opens the table once, in a Ray task, on every deltalake version. The task returns the version, schema and partition columns to the driver, and keeps the file list in the object store for the listing task. The driver never holds the file list, and the before-1.6/after-1.6 split is gone.

On moto, a read now sends no _delta_log request that V1 doesn't: 6 on the test table, against 6–8 for V1. If the stored file list is lost, or Ray rebuilds it by rerunning the task (which could read a newer version), the listing reopens the table at the pinned version.

)
rows = [row for m in manifests for t in reader.read(m) for row in t.to_pylist()]
assert sorted(row["id"] for row in rows) == [1, 2, 3, 4]
assert {row["grp"] for row in rows} == {"a b", "e=f", 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.

A few test tweaks:

  • Compare whole (id, grp) rows here: swapping two files' partition values still gives ids [1, 2, 3, 4] and the same grp set.
  • test_reader_opens_data_files_with_their_sizes_from_the_log repeats this test's setup; its unsized_opens == [] check can move here, which also covers the sizes after pickling.
  • In test_datasource_takes_schema_and_partitioning_from_the_log, the column-order asserts are the columns=None case of test_datasource_projects_columns_in_order, and category and schema_needs_file_sample are constants.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, all three. The test compares (id, grp) rows, the size check moved into it (so it runs on the pickled reader), and the duplicate asserts are gone. Merging also showed the old size test only passed because an earlier test imported deltalake.fs; the merged test imports it itself.

@abhishekverma-ray
abhishekverma-ray removed this pull request from stack #68288 November 19, 2026 04:25
@abhishekverma-ray abhishekverma-ray changed the title [Data][Delta DSv2][3/8] Add the Delta Lake DataSourceV2 datasource [Data][Delta DSv2][3/9] Add the Delta Lake DataSourceV2 datasource Nov 19, 2026
yield from super().read(input_split)

@override
def read_metadata(self, file_manifest: FileManifest) -> Iterator[BlockMetadata]:

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.

count() reads every data file's footer (one S3 GET per file), but the log the listing already loaded has each file's numRecords. Can the count come from the log?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in this PR. The whole-file listing that count() uses now carries each file's numRecords from the log to the reader, so count() opens no data file. A file whose writer recorded no stats still has its footer read. Tables with deletion vectors never reach V2, so the log counts are exact.

@abhishekverma-ray
abhishekverma-ray removed this pull request from stack #68331 November 20, 2026 17:29
@abhishekverma-ray abhishekverma-ray changed the title [Data][Delta DSv2][3/9] Add the Delta Lake DataSourceV2 datasource [Data][Delta DSv2][3/11] Add the Delta Lake DataSourceV2 datasource Nov 20, 2026

logger = logging.getLogger(__name__)

# Reader features the V2 reader handles. Tables that need others (deletion

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.

stale

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This describes the V1 fallback, which #68408 (before the flag flip) removes; that PR rewrites this text. I left it here because this layer still has the fallback.

include_paths: bool,
arrow_parquet_args: Dict[str, Any],
) -> Optional[str]:
"""Why ``table`` can't be read with :class:`DeltaDatasourceV2`, if it can't.

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.

stale

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This describes the V1 fallback, which #68408 (before the flag flip) removes; that PR rewrites this text. I left it here because this layer still has the fallback.

)
if include_paths and "path" in schema.names:
return "the table has its own `path` column and include_paths is set"
except Exception as e: # Fail closed: when in doubt, read with V1.

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.

stale

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This describes the V1 fallback, which #68408 (before the flag flip) removes; that PR rewrites this text. I left it here because this layer still has the fallback.


@DeveloperAPI
class DeltaDatasourceV2(DataSourceWithMetadata[FileManifest]):
"""V2 datasource for one version of a Delta Lake table."""

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.

can we specify which version? Why is this needed btw?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's the version table was opened at: read_delta's version=, or the latest version when read_delta is called. It's pinned so every listing task, retry and re-execution reads the same files: if someone writes to the table while the dataset is in use, the rows don't change and still match the schema read at the start. The class docstring says this now (61985d1).

)
self._synthesized_columns = (PathColumn(),) if include_paths else ()
if columns is not None:
# ``columns`` may name the ``path`` column, as with the V1 reader.

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.

not sure I understand this comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reworded in 61985d1: with include_paths=True, columns may include path, as with the V1 reader. It isn't a table column, so the unknown-column check has to accept it.

[name for name in projected if name not in synthesized] + synthesized
)
_validate_shuffle_arg(shuffle)
# ``_read_datasource_v2`` gives a metadata-backed source's listing no

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.

unclear

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reworded in 61985d1: shuffle="files" gets its seed once per dataset; each execution still shuffles differently because the seed is mixed with the execution number. The Delta listing applies the shuffle itself, since _read_datasource_v2 doesn't shuffle the listing of a source with metadata.

@@ -0,0 +1,146 @@
"""The filesystem the Delta reader reads a table through when the caller gives none.

It is ``deltalake``'s own, as ``DeltaTable.to_pyarrow_dataset`` uses: it takes

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.

unclear

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reworded in 61985d1: without a caller filesystem, the reader uses deltalake's own storage, the one V1 uses, so credentials from storage_options and URIs like az:// work the same. This module also gives it each file's size from the log, which saves a HEAD request per file on S3.

abhishekverma-ray and others added 6 commits November 23, 2026 15:51
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]>
…he log

- The table's default filesystem (deltalake's DeltaStorageHandler, now
  wrapped in DeltaTableFileSystemHandler) is told the log's file sizes:
  by the listing before the footer reads, and by DeltaFileReader for each
  manifest. Before, every open asked S3 for the size (a HEAD request),
  three per file. The handler is built on first use, so a task that
  receives it doesn't build one it then replaces.
- filesystem_for_sized_opens also unwraps a SubTreeFileSystem over S3,
  which is what a catalog's vended credentials give, so sized opens skip
  the HEAD there too.
- Docs no longer say the driver skips the file list: deltalake 1.6
  ignores without_files.
- Reader version 2 means column mapping; the fallback reason says so.
- The shuffle-seed comment says when the seed is drawn and why each
  execution still shuffles differently.
- DeltaScanner.prune_input_split removed: the base does the same.
- Unit tests: removed ones that repeated other tests, the eligibility
  check runs on a real table, and a test that the reader opens files with
  their sizes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Abhishek Verma <[email protected]>
- Compare whole (id, grp) rows after pickling, so swapped partition
  values fail the test.
- Fold the sizes-from-the-log check into the serialization test, so it
  runs on the pickled reader. Import deltalake.fs there: the old test
  only passed because an earlier test had imported it.
- Drop asserts on constants and the column-order asserts that
  test_datasource_projects_columns_in_order already covers.
- Say in delta_datasource_v2_unsupported_reason which tables V1 reads
  and which it rejects too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Abhishek Verma <[email protected]>
deltalake defines DeltaStorageHandler twice, so pyrefly rejects it as a
base class when the test imports it by name. Take the module from
pytest.importorskip, as the file does for deltalake itself.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Abhishek Verma <[email protected]>
count() read every data file's Parquet footer for its row count, one
request per file, although the Delta log the listing already loaded
records each file's numRecords. The whole-file listing that count()
uses now carries those counts to the reader, which reads a footer only
for a file whose writer recorded no stats. Tables with deletion
vectors, whose counts include deleted rows, never reach this reader.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Abhishek Verma <[email protected]>
Say which version DeltaDatasourceV2 reads and why it's pinned, and
reword the comments on the path column in columns, the shuffle seed and
the default filesystem. Comments only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Abhishek Verma <[email protected]>
@abhishekverma-ray
abhishekverma-ray force-pushed the abhishek/delta-dsv2-3-datasource branch from 61985d1 to 0c4b347 Compare November 23, 2026 10:26
@sampan-s-nayak
sampan-s-nayak enabled stacked auto-merge (squash) November 23, 2026 10:32
@sampan-s-nayak
sampan-s-nayak merged commit f014a86 into master Nov 23, 2026
5 checks passed
@sampan-s-nayak
sampan-s-nayak deleted the abhishek/delta-dsv2-3-datasource branch November 23, 2026 11:13
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.

3 participants