Skip to content

[Data] DSv2 Reorg [1/6]: Complete the DataSourceV2 contract for non-Parquet datasources - #66066

Merged
goutamvenkat-anyscale merged 16 commits into
ray-project:masterfrom
AarryaSaraf:bug_fix_5
Sep 19, 2026
Merged

goutamvenkat-anyscale merged 16 commits into
ray-project:masterfrom
AarryaSaraf:bug_fix_5

Conversation

@AarryaSaraf

@AarryaSaraf AarryaSaraf commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Description

Second PR of the DSv2 Reorg series ([0/6] … [6/6]), stacked on #66244
([0/6]); the diff shows both until that one merges.

_read_datasource_v2 in read_api.py reads four attributes and calls one
method that DataSourceV2 never declared. Parquet defines them all, so it
worked; any other datasource that implemented only the abstract methods failed
with AttributeError inside the read code. After this PR, implementing the
abstract members of DataSourceV2 is enough for a new datasource to work end
to end, and a missing one is reported at construction. No behavior change for
Parquet.

flowchart LR
  R[read_api._read_datasource_v2] -->|reads paths, filesystem, file_extensions, shuffle; calls _get_file_indexer| D[DataSourceV2 base class]
  D -->|abstract: paths, filesystem, _get_file_indexer| S[new datasource subclass]
  D -->|default None: file_extensions, shuffle| S
Loading

Changes

  1. Declare everything the read code uses on DataSourceV2: paths,
    filesystem, _get_file_indexer abstract; file_extensions, shuffle
    default None.
  2. filesystem may be None, for sources that read through their own
    library (PyIceberg, Lance, hudi-rs).
  3. FileScanner.prune_manifest → Scanner.prune_input_split, so partition
    pruning runs for every scanner, not only FileScanner subclasses.
  4. FileIndexer docstring updated for the per-file listing contract left
    after [Data] DSv2 Reorg [0/6]: Remove FileChunker #66244.

Additional information

Not a duplicate: no open PR changes the DataSourceV2 base class. #65887 and
#65888 also touch file_indexer.py / listing_utils.py, so expect small merge
conflicts there.

Tests run locally from this branch (macOS, ~/ray/.venv), from python/ray/data:

pytest -q tests/unit/datasource_v2                     # 119 passed
pytest -q tests/datasource/test_read_parquet_v2.py     # 37 passed
pytest -q tests/datasource/test_parquet.py             # 246 passed, 13 skipped, 34 errors

The 34 errors are moto s3_fs fixture setup errors (moto_server not on
PATH), identical on master. ruff, black and pydoclint at the pre-commit
pins are clean; pyrefly reports the same pre-existing errors as the base
commit.

Written with Claude Code; I reviewed every changed line and ran the tests above.

🤖 Generated with Claude Code

@AarryaSaraf AarryaSaraf added the data Ray Data-related issues label Sep 10, 2026
@AarryaSaraf
AarryaSaraf marked this pull request as ready for review September 10, 2026 22:40
@AarryaSaraf
AarryaSaraf requested a review from a team as a code owner September 10, 2026 22:40
@AarryaSaraf AarryaSaraf added the go add ONLY when ready to merge, run all tests label Sep 10, 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 refactors the DataSourceV2 and Scanner interfaces to clarify framework contracts, particularly for non-file-based sources. It introduces abstract properties paths and filesystem on DataSourceV2, makes _get_file_indexer abstract, and allows filesystem to be optional across listing utilities and FileIndexer. Additionally, prune_manifest is moved from FileScanner to the base Scanner class. Feedback on these changes highlights a potential Liskov Substitution Principle (LSP) violation and type-checking errors because subclass implementations of FileIndexer were not updated to accept Optional["FileSystem"].

paths: "BlockColumn",
*,
filesystem: "FileSystem",
filesystem: Optional["FileSystem"],

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

Changing the filesystem parameter to Optional["FileSystem"] in the base class FileIndexer.list_files (and similarly for list_file_infos on line 104) without updating the corresponding subclass implementations (such as NonSamplingFileIndexer and FooterFileIndexer) violates the Liskov Substitution Principle (LSP).\n\nThis will cause static type checkers (like MyPy or Pyright) to raise incompatible override errors. Additionally, if a caller passes None to a FileIndexer reference that is instantiated as one of these subclasses, it will fail with an unhelpful runtime error.\n\nRecommendation: Update the signatures of list_files and list_file_infos in all subclasses of FileIndexer to accept Optional["FileSystem"], and add an explicit runtime check or assertion at the beginning of their implementations, for example:\npython\nassert filesystem is not None, "NonSamplingFileIndexer requires a valid filesystem."\n

AarryaSaraf and others added 2 commits September 10, 2026 16:45
…verride

Pyrefly flags the Scanner.prune_manifest(input_split) base against
ArrowFileScanner.prune_manifest(manifest) as an inconsistent override.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Aarrya <[email protected]>
…lingFileIndexer

The FileIndexer base now accepts filesystem=None for indexers that do their
own IO. NonSamplingFileIndexer (and FooterFileIndexer through it) cannot, so
their signatures accept the base type and list_file_infos raises a ValueError
naming the indexer instead of failing on a None attribute inside path
expansion. Addresses the review comment on file_indexer.py.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Aarrya <[email protected]>
return self._file_chunker

@override
def as_whole_file_indexer(self) -> "NonSamplingFileIndexer":

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.

This function appears to be implemented twice.

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 is in a separate class. I am not sure I understand. This is an override on the base

@@ -210,12 +215,12 @@

@property
def file_chunker(self) -> FileChunker:

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.

We should split up file chunker from the file indexer

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.

Had that planned for a later iteration. This is just about declaration closure in DSv2

def __post_init__(self) -> None:
_validate_shuffle_arg(self.shuffle)

def prune_manifest(self, manifest: FileManifest) -> FileManifest:

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.

Why is this being removed?

@AarryaSaraf AarryaSaraf Sep 11, 2026 •

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.

Its being shifted not removed, see point 2


@property
def filesystem(self) -> Optional["FileSystem"]:
def filesystem(self) -> "FileSystem":

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.

why is the signature changing?

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 is parquet specific. I don't see it returning None. Do you see such a use case?

"""
return False

def prune_manifest(self, manifest: InputSplit) -> InputSplit:

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.

Wait non file scanners don't have manifests. Think about Databases for example

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.

Youre right. Will update.

@rayhhome rayhhome 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.

Logic looks fine; some of the comments/docstrings seem a bit wordy, can you make them more concise?

...
"""Turns root paths into ``FileManifest`` blocks inside ``ListFiles`` tasks.

Chosen by ``DataSourceV2._get_file_indexer``. How an implementation splits a

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.

I think excluding file_chunker from FileIndexer already implies what this comment here explains, so I feel this comment might be unnecessary?

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.

I think we should mention why its separate but I do feel 4 lines is too much. Ill compact it.

…trim docstrings

Scanner is generic over InputSplit, so the method it gained in this PR should
not be named after the file-based case: a database-backed scanner has splits,
not manifests. Renamed on the base and on ArrowFileScanner's override, with the
parameter named input_split to match Reader.read. This also removes the
override/base parameter mismatch the earlier pyrefly fix worked around.

Shortened the docstrings and comments this PR added, per review.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Aarrya <[email protected]>
@AarryaSaraf AarryaSaraf changed the title [Data] DSv2 Reorg [1/5]: Complete the DataSourceV2 contract for non-Parquet datasources [Data] DSv2 Reorg [1/6]: Complete the DataSourceV2 contract for non-Parquet datasources Sep 15, 2026
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Aarrya <[email protected]>
Signed-off-by: Aarrya <[email protected]>

# Conflicts:
#	python/ray/data/_internal/datasource_v2/listing/file_indexer.py
#	python/ray/data/_internal/logical/operators/read_operator.py
@AarryaSaraf
AarryaSaraf marked this pull request as draft September 17, 2026 19:12
goutamvenkat-anyscale pushed a commit that referenced this pull request Sep 18, 2026
## Why

`FileChunker` let a `FileIndexer` split one listed file into several
manifest rows. Nothing uses that seam any more: Parquet splits by row
group inside `FooterFileIndexer`'s footer read, every other indexer
emits one row per file, and `FilePartitioner` groups files into read
tasks. What remained was an abstract property every indexer had to
implement, a `WholeFileChunker` that returned its input unchanged, and a
`LineDelimitedFileChunker` with no callers outside its own tests.

First PR of the DSv2 reorg series; #66066 and the follow-ups will be
rebased onto it.

## What changes

- Delete `FileChunker`, `WholeFileChunker`, `LineDelimitedFileChunker`
and `LineDelimitedFileChunkMetadata`. The module keeps the manifest
metadata types (`ChunkMetadata`, `create_chunk_metadata`,
`ParquetRowGroupChunkMetadata`) that `OnlineBinPacker`,
`FooterFileIndexer` and `FileManifest` still use.
  Files: `datasource_v2/chunkers/file_chunker.py`
- `FileIndexer` drops the abstract `file_chunker` property.
`NonSamplingFileIndexer` drops the constructor argument and property,
and emits one manifest row per file with `None` chunk metadata.
  Files: `datasource_v2/listing/file_indexer.py`
- Remove two stale comments naming a `StreamingFileChunker` that never
existed.
Files: `datasource_v2/readers/parquet_file_reader.py`,
`logical/operators/read_operator.py`
- Tests: `test_file_chunker.py` becomes `test_chunk_metadata.py`
(metadata types only); chunker cases dropped from `test_file_indexer.py`
and `test_read_parquet_v2.py`.

## Example

Before, an indexer that lists whole files still had to answer the
chunker question:

```python
class MyIndexer(FileIndexer):
    @Property
    def file_chunker(self) -> FileChunker:   # required; always WholeFileChunker()
        return WholeFileChunker()

    def list_files(self, ctx): ...
```

After:

```python
class MyIndexer(FileIndexer):
    def list_files(self, ctx): ...
```

`read_parquet` behaviour is unchanged: `FooterFileIndexer` never used
the chunker it inherited. Net diff is +37 / −287 lines.

## Checks

Lint: ruff, ruff `--select I`, black, pydoclint with the CI flags, `git
diff --check`. Type check: pyrefly on `python/ray/data`, no errors in
the touched files.

Tests run locally:

```
pytest python/ray/data/tests/unit/datasource_v2                          # 217 passed
pytest python/ray/data/tests/datasource/test_read_parquet_v2.py          # 37 passed
pytest python/ray/data/tests/test_parquet.py                             # 246 passed, 13 skipped (34 pre-existing moto fixture errors)
pytest python/ray/data/tests/test_execution_optimizer_limit_pushdown.py  # 28 passed
pytest python/ray/data/tests/test_predicate_pushdown.py                  # 51 passed, 2 skipped
```

Not a duplicate: the only open PR mentioning `FileChunker` is #66066, my
own follow-up in this series. #64540 (ORC) adds an `OrcFileChunker` and
will need to drop it when it rebases.

Written with AI assistance (Claude Code). Every changed line was
reviewed by me and the tests above were run locally.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: Aarrya <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
Same change rebuilt on top of ray-project#66244 (PR 0); the tree is identical to e631f0e.

Signed-off-by: Aarrya <[email protected]>
@AarryaSaraf
AarryaSaraf marked this pull request as ready for review September 18, 2026 23:14
@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!

Comment on lines +74 to +78
A datasource answers two questions for a read: where the data is
(``paths``, ``filesystem``, ``_get_file_indexer``) and how to read it
(``infer_schema``, ``create_scanner``). Everything the read pipeline
needs is declared on this class, so implementing the abstract members is
enough for a new source to work end to end.

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.

Don't remove the responsibilities of the datasourceV2 api

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.

The description is too vague

@goutamvenkat-anyscale
goutamvenkat-anyscale merged commit 0c6dcfb into ray-project:master Sep 19, 2026
6 checks passed
goutamvenkat-anyscale pushed a commit that referenced this pull request Sep 21, 2026
…Metadata` as the two bases every datasource extends (#66312)

## Description

Sits between `[1/6]` (#66066) and `[2/6]` in the DSv2 Reorg series,
stacked
on #66066; the diff shows both until that one merges.

`DataSourceV2` asks every datasource for a PyArrow `filesystem`, a list
of
`file_extensions` and a file `shuffle`. Those only mean something when
Ray
walks a filesystem to find the files. A source whose indexer already
knows its
data, such as Iceberg or a database, had to return `None` for all three
just to
satisfy the contract. This PR gives the base class two subclasses and
every
datasource extends one of them. No behavior change for Parquet.

```mermaid
classDiagram
    class DataSourceV2 {
        <<abstract>>
        paths()*
        _get_file_indexer()*
        schema_needs_file_sample()*
        infer_schema(sample)*
        create_scanner(schema, filesystem, ...)*
    }
    class FileDataSourceV2 {
        <<abstract>>
        filesystem()* never None
        file_extensions() = None
        shuffle() = None
    }
    class DataSourceWithMetadata {
        <<abstract>>
        schema_needs_file_sample() = False
    }
    DataSourceV2 <|-- FileDataSourceV2 : Ray lists files through a filesystem
    DataSourceV2 <|-- DataSourceWithMetadata : the source finds its own data
    FileDataSourceV2 <|-- ParquetDatasourceV2
    DataSourceWithMetadata <|-- IcebergDatasourceV2 : later, same for Delta and SQL
```

### Changes

1. `FileDataSourceV2`: `filesystem` abstract and never `None`;
`file_extensions` and `shuffle` default `None`. The three members leave
   the base class. `ParquetDatasourceV2` extends it.
2. `DataSourceWithMetadata`: `schema_needs_file_sample` defaults to
`False`, since
   the schema comes from the same metadata as the listing.
3. `_read_datasource_v2` reads the three file members from a
`FileDataSourceV2`, passes `None` for a `DataSourceWithMetadata`, and
rejects a
   class that extends the base directly.
4. Contract tests in `tests/unit/datasource_v2/test_datasource_v2.py`.

## Additional information

Not a duplicate: no open PR changes the `DataSourceV2` class hierarchy.
The
open CSV migration (#65743) is a plain file format and would extend
`FileDataSourceV2` after a rebase.

Tests run locally from this branch (macOS, `~/ray/.venv`), from
`python/ray/data`:

```
pytest -q tests/unit/datasource_v2                     # 126 passed
pytest -q tests/datasource/test_read_parquet_v2.py     # 37 passed
pytest -q tests/datasource/test_parquet.py             # 246 passed, 13 skipped, 34 errors
```

The 34 errors are moto `s3_fs` fixture setup errors (`moto_server` not
on
PATH), identical on master. `ruff`, `black` and `pydoclint` at the
pre-commit
pins are clean; `pyrefly` reports the same 61 pre-existing errors as the
base
commit.

Written with Claude Code; I reviewed every changed line and ran the
tests above.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Aarrya <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
owenowenisme pushed a commit to owenowenisme/ray that referenced this pull request Sep 23, 2026
…Metadata` as the two bases every datasource extends (ray-project#66312)

## Description

Sits between `[1/6]` (ray-project#66066) and `[2/6]` in the DSv2 Reorg series,
stacked
on ray-project#66066; the diff shows both until that one merges.

`DataSourceV2` asks every datasource for a PyArrow `filesystem`, a list
of
`file_extensions` and a file `shuffle`. Those only mean something when
Ray
walks a filesystem to find the files. A source whose indexer already
knows its
data, such as Iceberg or a database, had to return `None` for all three
just to
satisfy the contract. This PR gives the base class two subclasses and
every
datasource extends one of them. No behavior change for Parquet.

```mermaid
classDiagram
    class DataSourceV2 {
        <<abstract>>
        paths()*
        _get_file_indexer()*
        schema_needs_file_sample()*
        infer_schema(sample)*
        create_scanner(schema, filesystem, ...)*
    }
    class FileDataSourceV2 {
        <<abstract>>
        filesystem()* never None
        file_extensions() = None
        shuffle() = None
    }
    class DataSourceWithMetadata {
        <<abstract>>
        schema_needs_file_sample() = False
    }
    DataSourceV2 <|-- FileDataSourceV2 : Ray lists files through a filesystem
    DataSourceV2 <|-- DataSourceWithMetadata : the source finds its own data
    FileDataSourceV2 <|-- ParquetDatasourceV2
    DataSourceWithMetadata <|-- IcebergDatasourceV2 : later, same for Delta and SQL
```

### Changes

1. `FileDataSourceV2`: `filesystem` abstract and never `None`;
`file_extensions` and `shuffle` default `None`. The three members leave
   the base class. `ParquetDatasourceV2` extends it.
2. `DataSourceWithMetadata`: `schema_needs_file_sample` defaults to
`False`, since
   the schema comes from the same metadata as the listing.
3. `_read_datasource_v2` reads the three file members from a
`FileDataSourceV2`, passes `None` for a `DataSourceWithMetadata`, and
rejects a
   class that extends the base directly.
4. Contract tests in `tests/unit/datasource_v2/test_datasource_v2.py`.

## Additional information

Not a duplicate: no open PR changes the `DataSourceV2` class hierarchy.
The
open CSV migration (ray-project#65743) is a plain file format and would extend
`FileDataSourceV2` after a rebase.

Tests run locally from this branch (macOS, `~/ray/.venv`), from
`python/ray/data`:

```
pytest -q tests/unit/datasource_v2                     # 126 passed
pytest -q tests/datasource/test_read_parquet_v2.py     # 37 passed
pytest -q tests/datasource/test_parquet.py             # 246 passed, 13 skipped, 34 errors
```

The 34 errors are moto `s3_fs` fixture setup errors (`moto_server` not
on
PATH), identical on master. `ruff`, `black` and `pydoclint` at the
pre-commit
pins are clean; `pyrefly` reports the same 61 pre-existing errors as the
base
commit.

Written with Claude Code; I reviewed every changed line and ran the
tests above.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Aarrya <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
## Why

`FileChunker` let a `FileIndexer` split one listed file into several
manifest rows. Nothing uses that seam any more: Parquet splits by row
group inside `FooterFileIndexer`'s footer read, every other indexer
emits one row per file, and `FilePartitioner` groups files into read
tasks. What remained was an abstract property every indexer had to
implement, a `WholeFileChunker` that returned its input unchanged, and a
`LineDelimitedFileChunker` with no callers outside its own tests.

First PR of the DSv2 reorg series; ray-project#66066 and the follow-ups will be
rebased onto it.

## What changes

- Delete `FileChunker`, `WholeFileChunker`, `LineDelimitedFileChunker`
and `LineDelimitedFileChunkMetadata`. The module keeps the manifest
metadata types (`ChunkMetadata`, `create_chunk_metadata`,
`ParquetRowGroupChunkMetadata`) that `OnlineBinPacker`,
`FooterFileIndexer` and `FileManifest` still use.
  Files: `datasource_v2/chunkers/file_chunker.py`
- `FileIndexer` drops the abstract `file_chunker` property.
`NonSamplingFileIndexer` drops the constructor argument and property,
and emits one manifest row per file with `None` chunk metadata.
  Files: `datasource_v2/listing/file_indexer.py`
- Remove two stale comments naming a `StreamingFileChunker` that never
existed.
Files: `datasource_v2/readers/parquet_file_reader.py`,
`logical/operators/read_operator.py`
- Tests: `test_file_chunker.py` becomes `test_chunk_metadata.py`
(metadata types only); chunker cases dropped from `test_file_indexer.py`
and `test_read_parquet_v2.py`.

## Example

Before, an indexer that lists whole files still had to answer the
chunker question:

```python
class MyIndexer(FileIndexer):
    @Property
    def file_chunker(self) -> FileChunker:   # required; always WholeFileChunker()
        return WholeFileChunker()

    def list_files(self, ctx): ...
```

After:

```python
class MyIndexer(FileIndexer):
    def list_files(self, ctx): ...
```

`read_parquet` behaviour is unchanged: `FooterFileIndexer` never used
the chunker it inherited. Net diff is +37 / −287 lines.

## Checks

Lint: ruff, ruff `--select I`, black, pydoclint with the CI flags, `git
diff --check`. Type check: pyrefly on `python/ray/data`, no errors in
the touched files.

Tests run locally:

```
pytest python/ray/data/tests/unit/datasource_v2                          # 217 passed
pytest python/ray/data/tests/datasource/test_read_parquet_v2.py          # 37 passed
pytest python/ray/data/tests/test_parquet.py                             # 246 passed, 13 skipped (34 pre-existing moto fixture errors)
pytest python/ray/data/tests/test_execution_optimizer_limit_pushdown.py  # 28 passed
pytest python/ray/data/tests/test_predicate_pushdown.py                  # 51 passed, 2 skipped
```

Not a duplicate: the only open PR mentioning `FileChunker` is ray-project#66066, my
own follow-up in this series. ray-project#64540 (ORC) adds an `OrcFileChunker` and
will need to drop it when it rebases.

Written with AI assistance (Claude Code). Every changed line was
reviewed by me and the tests above were run locally.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: Aarrya <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…arquet datasources (ray-project#66066)

## Description

Second PR of the DSv2 Reorg series (`[0/6]` … `[6/6]`), stacked on
ray-project#66244
(`[0/6]`); the diff shows both until that one merges.

`_read_datasource_v2` in `read_api.py` reads four attributes and calls
one
method that `DataSourceV2` never declared. Parquet defines them all, so
it
worked; any other datasource that implemented only the abstract methods
failed
with `AttributeError` inside the read code. After this PR, implementing
the
abstract members of `DataSourceV2` is enough for a new datasource to
work end
to end, and a missing one is reported at construction. No behavior
change for
Parquet.

```mermaid
flowchart LR
  R[read_api._read_datasource_v2] -->|reads paths, filesystem, file_extensions, shuffle; calls _get_file_indexer| D[DataSourceV2 base class]
  D -->|abstract: paths, filesystem, _get_file_indexer| S[new datasource subclass]
  D -->|default None: file_extensions, shuffle| S
```

### Changes

1. Declare everything the read code uses on `DataSourceV2`: `paths`,
`filesystem`, `_get_file_indexer` abstract; `file_extensions`, `shuffle`
   default `None`.
2. `filesystem` may be `None`, for sources that read through their own
   library (PyIceberg, Lance, hudi-rs).
3. `FileScanner.prune_manifest` → `Scanner.prune_input_split`, so
partition
   pruning runs for every scanner, not only `FileScanner` subclasses.
4. `FileIndexer` docstring updated for the per-file listing contract
left
   after ray-project#66244.

## Additional information

Not a duplicate: no open PR changes the `DataSourceV2` base class.
ray-project#65887 and
ray-project#65888 also touch `file_indexer.py` / `listing_utils.py`, so expect
small merge
conflicts there.

Tests run locally from this branch (macOS, `~/ray/.venv`), from
`python/ray/data`:

```
pytest -q tests/unit/datasource_v2                     # 119 passed
pytest -q tests/datasource/test_read_parquet_v2.py     # 37 passed
pytest -q tests/datasource/test_parquet.py             # 246 passed, 13 skipped, 34 errors
```

The 34 errors are moto `s3_fs` fixture setup errors (`moto_server` not
on
PATH), identical on master. `ruff`, `black` and `pydoclint` at the
pre-commit
pins are clean; `pyrefly` reports the same pre-existing errors as the
base
commit.

Written with Claude Code; I reviewed every changed line and ran the
tests above.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Aarrya <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…Metadata` as the two bases every datasource extends (ray-project#66312)

## Description

Sits between `[1/6]` (ray-project#66066) and `[2/6]` in the DSv2 Reorg series,
stacked
on ray-project#66066; the diff shows both until that one merges.

`DataSourceV2` asks every datasource for a PyArrow `filesystem`, a list
of
`file_extensions` and a file `shuffle`. Those only mean something when
Ray
walks a filesystem to find the files. A source whose indexer already
knows its
data, such as Iceberg or a database, had to return `None` for all three
just to
satisfy the contract. This PR gives the base class two subclasses and
every
datasource extends one of them. No behavior change for Parquet.

```mermaid
classDiagram
    class DataSourceV2 {
        <<abstract>>
        paths()*
        _get_file_indexer()*
        schema_needs_file_sample()*
        infer_schema(sample)*
        create_scanner(schema, filesystem, ...)*
    }
    class FileDataSourceV2 {
        <<abstract>>
        filesystem()* never None
        file_extensions() = None
        shuffle() = None
    }
    class DataSourceWithMetadata {
        <<abstract>>
        schema_needs_file_sample() = False
    }
    DataSourceV2 <|-- FileDataSourceV2 : Ray lists files through a filesystem
    DataSourceV2 <|-- DataSourceWithMetadata : the source finds its own data
    FileDataSourceV2 <|-- ParquetDatasourceV2
    DataSourceWithMetadata <|-- IcebergDatasourceV2 : later, same for Delta and SQL
```

### Changes

1. `FileDataSourceV2`: `filesystem` abstract and never `None`;
`file_extensions` and `shuffle` default `None`. The three members leave
   the base class. `ParquetDatasourceV2` extends it.
2. `DataSourceWithMetadata`: `schema_needs_file_sample` defaults to
`False`, since
   the schema comes from the same metadata as the listing.
3. `_read_datasource_v2` reads the three file members from a
`FileDataSourceV2`, passes `None` for a `DataSourceWithMetadata`, and
rejects a
   class that extends the base directly.
4. Contract tests in `tests/unit/datasource_v2/test_datasource_v2.py`.

## Additional information

Not a duplicate: no open PR changes the `DataSourceV2` class hierarchy.
The
open CSV migration (ray-project#65743) is a plain file format and would extend
`FileDataSourceV2` after a rebase.

Tests run locally from this branch (macOS, `~/ray/.venv`), from
`python/ray/data`:

```
pytest -q tests/unit/datasource_v2                     # 126 passed
pytest -q tests/datasource/test_read_parquet_v2.py     # 37 passed
pytest -q tests/datasource/test_parquet.py             # 246 passed, 13 skipped, 34 errors
```

The 34 errors are moto `s3_fs` fixture setup errors (`moto_server` not
on
PATH), identical on master. `ruff`, `black` and `pydoclint` at the
pre-commit
pins are clean; `pyrefly` reports the same 61 pre-existing errors as the
base
commit.

Written with Claude Code; I reviewed every changed line and ran the
tests above.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Aarrya <[email protected]>
Co-authored-by: Claude Fable 5.1 <[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