Skip to content

[Data] DSv2 Reorg [1.5/6]: Add FileDataSourceV2 and DataSourceWithMetadata as the two bases every datasource extends - #66312

Merged
goutamvenkat-anyscale merged 9 commits into
ray-project:masterfrom
AarryaSaraf:dsv2-split-file-datasource
Sep 21, 2026
Merged

goutamvenkat-anyscale merged 9 commits into
ray-project:masterfrom
AarryaSaraf:dsv2-split-file-datasource

Conversation

@AarryaSaraf

@AarryaSaraf AarryaSaraf commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

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.

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
Loading

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

@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!

@AarryaSaraf
AarryaSaraf marked this pull request as ready for review September 19, 2026 18:04
@AarryaSaraf
AarryaSaraf requested a review from a team as a code owner September 19, 2026 18:04

@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 API by removing the FileChunker abstraction and splitting DataSourceV2 into two explicit subclasses: FileDataSourceV2 for filesystem-based sources and TableDataSourceV2 for catalog- or database-backed sources. Additionally, prune_manifest has been generalized to prune_input_split on the scanner interface. The review feedback highlights a critical issue in plan_read_files_op.py where FileManifest is hardcoded, which breaks the generic InputSplit design for table-based sources. It also suggests renaming file_chunker.py to reflect its new role as a metadata-only module and adding a default schema_needs_file_sample implementation in FileDataSourceV2 to reduce boilerplate.

manifest = FileManifest(block)
if isinstance(scanner, FileScanner):
manifest = scanner.prune_manifest(manifest)
manifest = scanner.prune_input_split(FileManifest(block))

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

The code here hardcodes wrapping the block in FileManifest: scanner.prune_input_split(FileManifest(block)). This assumes that the InputSplit type for all scanners is always FileManifest. However, TableDataSourceV2 is generic over InputSplit (i.e., TableDataSourceV2[InputSplit]), allowing custom table-based datasources to define their own input split types. Hardcoding FileManifest(block) here will cause runtime failures or type errors for any TableDataSourceV2 subclass that uses a custom InputSplit type instead of FileManifest. Consider making the wrapping of the block into an InputSplit generic or delegated to the scanner/datasource, or at least check if the scanner is a FileScanner before wrapping.

@@ -1,26 +1,12 @@
"""File chunkers for DataSourceV2.
"""Per-row chunk metadata carried by a ``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.

medium

The file file_chunker.py no longer contains any FileChunker implementations or chunking logic, as they have been removed in this PR. It now only contains ChunkMetadata and ParquetRowGroupChunkMetadata definitions. To improve maintainability and avoid confusion, consider renaming this file to chunk_metadata.py or moving these definitions to a more appropriate module (e.g., file_manifest.py).

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 lands in PR 5/6

Comment on lines +285 to +288
@property
def file_extensions(self) -> Optional[List[str]]:
"""File extensions to keep while listing; ``None`` keeps every file."""
return None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Since almost all file-based sources (e.g., CSV, JSON, Parquet) need to sample a file to infer their schema, consider providing a default implementation of schema_needs_file_sample returning True on FileDataSourceV2. This will reduce boilerplate for subclasses of FileDataSourceV2 and make the base class easier to extend.

Suggested change
@property
def file_extensions(self) -> Optional[List[str]]:
"""File extensions to keep while listing; ``None`` keeps every file."""
return None
@property
def schema_needs_file_sample(self) -> bool:
return True
@property
def file_extensions(self) -> Optional[List[str]]:
return None

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.

reason for keeping it abstract: adding a datasource forces the question

@ray-gardener ray-gardener Bot added the data Ray Data-related issues label Sep 19, 2026
@AarryaSaraf AarryaSaraf added the go add ONLY when ready to merge, run all tests label Sep 19, 2026
…atasource

Signed-off-by: Aarrya <[email protected]>

# Conflicts:
#	python/ray/data/_internal/datasource_v2/datasource_v2.py
#	python/ray/data/read_api.py


@DeveloperAPI
class TableDataSourceV2(DataSourceV2[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.

Why is this called TableDataSourceV2?

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.

CatalogDataSourceV2 would make more sense

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.

Catalog does seem like a better name. I chose file and table because tables intuitively would abstract away file system work

…Metadata

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Aarrya <[email protected]>
@goutamvenkat-anyscale goutamvenkat-anyscale changed the title [Data] DSv2 Reorg [1.5/6]: Add FileDataSourceV2 and TableDataSourceV2 as the two bases every datasource extends [Data] DSv2 Reorg [1.5/6]: Add FileDataSourceV2 and DataSourceWithMetadata as the two bases every datasource extends Sep 21, 2026
@goutamvenkat-anyscale
goutamvenkat-anyscale merged commit 7204ade into ray-project:master Sep 21, 2026
6 checks passed
goutamvenkat-anyscale pushed a commit that referenced this pull request Sep 22, 2026
… datasource package (#66357)

## Description

Third PR of the DSv2 Reorg series, on top of #66312 (`[1.5/6]`).

`datasource_v2` still imports helpers from the legacy
`parquet_datasource.py`.
This PR moves them into `datasource_v2`, points the legacy module at
their new
homes, and adds a lint so the dependency only ever points one way:
legacy may
depend on V2, never the reverse. No behavior change.

### What moved where

1. Eight Parquet-only helpers (legacy tensor check, nested-type fallback
sizing, leaf-column resolution, row-group size, the Arrow chunk limit)
move
   from the legacy module into new `datasource_v2/parquet_utils.py`.
2. The predicate helpers `combine_predicates` and
`_split_predicate_by_columns`
move from the legacy module into `datasource_v2/pushdown.py`, which is
`logical_optimizers.py` renamed because it now holds all pushdown code.
3. `_compute_row_hashes` moves from the legacy module into
   `datasource_v2/readers/file_reader.py`.
4. The legacy `parquet_datasource.py` imports all of the above back from
V2.
5. New lint `ci/lint/check_datasource_v2_imports.py` fails on any V2
import of
the legacy package, module-level or function-level, wired into
pre-commit
   and `lint.sh`.

### Code changes summarized

- The Parquet extension list moves to `PARQUET_FILE_EXTENSIONS` in
  `parquet_utils.py`; both `ParquetDatasourceV2` and the legacy
  `ParquetDatasource._FILE_EXTENSIONS` read it from there.
- `check_for_legacy_tensor_type` gained type annotations on the move.
- `parquet_file_reader.py` imports the moved helpers at module level
instead
of inside the fallback method. The function-level import existed to
dodge an
  import cycle through the legacy module and its twenty Ray imports;
`parquet_utils.py` imports only `typing` and `pyarrow`, so the reason is
  gone. Import errors now surface at load time rather than on the first
oversized nested-type file, and tests can patch the names on the reader
  module.
- `_compute_row_hashes` lives in `file_reader.py` rather than
`parquet_utils.py` because it is not Parquet code: it makes the
`row_hash`
column for every format, and the generic `FileReader` is its only V2
caller.
- The legacy module's `ray.data.expressions` import shrinks from
`BinaryExpr, Expr, Operation` to `Expr`. The two dropped names were used
only
by the moved `_split_predicate_by_columns`; `Expr` still annotates a
legacy
  method parameter.
- One `test_parquet.py` test patches the nested-type helper at both the
legacy
path and the reader path, since each reader now resolves it through its
own
  module.

## Additional information

Not a duplicate: no open PR moves these helpers or adds an import
boundary for
`datasource_v2`. #65743 (CSV on DatasourceV2) touches the package but
not
these modules.

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

```
python ci/lint/check_datasource_v2_imports.py                                  # clean
pytest -q tests/unit/datasource_v2 tests/unit/test_parquet_predicate_split.py  # 159 passed
pytest -q tests/datasource/test_read_parquet_v2.py                             # 37 passed
pytest -q tests/test_execution_optimizer_limit_pushdown.py                     # 28 passed
```

`ruff`, `black` and `pydoclint` at the pre-commit pins are clean;
`pyrefly`
reports the same 60 pre-existing errors as master.

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
…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
… datasource package (ray-project#66357)

## Description

Third PR of the DSv2 Reorg series, on top of ray-project#66312 (`[1.5/6]`).

`datasource_v2` still imports helpers from the legacy
`parquet_datasource.py`.
This PR moves them into `datasource_v2`, points the legacy module at
their new
homes, and adds a lint so the dependency only ever points one way:
legacy may
depend on V2, never the reverse. No behavior change.

### What moved where

1. Eight Parquet-only helpers (legacy tensor check, nested-type fallback
sizing, leaf-column resolution, row-group size, the Arrow chunk limit)
move
   from the legacy module into new `datasource_v2/parquet_utils.py`.
2. The predicate helpers `combine_predicates` and
`_split_predicate_by_columns`
move from the legacy module into `datasource_v2/pushdown.py`, which is
`logical_optimizers.py` renamed because it now holds all pushdown code.
3. `_compute_row_hashes` moves from the legacy module into
   `datasource_v2/readers/file_reader.py`.
4. The legacy `parquet_datasource.py` imports all of the above back from
V2.
5. New lint `ci/lint/check_datasource_v2_imports.py` fails on any V2
import of
the legacy package, module-level or function-level, wired into
pre-commit
   and `lint.sh`.

### Code changes summarized

- The Parquet extension list moves to `PARQUET_FILE_EXTENSIONS` in
  `parquet_utils.py`; both `ParquetDatasourceV2` and the legacy
  `ParquetDatasource._FILE_EXTENSIONS` read it from there.
- `check_for_legacy_tensor_type` gained type annotations on the move.
- `parquet_file_reader.py` imports the moved helpers at module level
instead
of inside the fallback method. The function-level import existed to
dodge an
  import cycle through the legacy module and its twenty Ray imports;
`parquet_utils.py` imports only `typing` and `pyarrow`, so the reason is
  gone. Import errors now surface at load time rather than on the first
oversized nested-type file, and tests can patch the names on the reader
  module.
- `_compute_row_hashes` lives in `file_reader.py` rather than
`parquet_utils.py` because it is not Parquet code: it makes the
`row_hash`
column for every format, and the generic `FileReader` is its only V2
caller.
- The legacy module's `ray.data.expressions` import shrinks from
`BinaryExpr, Expr, Operation` to `Expr`. The two dropped names were used
only
by the moved `_split_predicate_by_columns`; `Expr` still annotates a
legacy
  method parameter.
- One `test_parquet.py` test patches the nested-type helper at both the
legacy
path and the reader path, since each reader now resolves it through its
own
  module.

## Additional information

Not a duplicate: no open PR moves these helpers or adds an import
boundary for
`datasource_v2`. ray-project#65743 (CSV on DatasourceV2) touches the package but
not
these modules.

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

```
python ci/lint/check_datasource_v2_imports.py                                  # clean
pytest -q tests/unit/datasource_v2 tests/unit/test_parquet_predicate_split.py  # 159 passed
pytest -q tests/datasource/test_read_parquet_v2.py                             # 37 passed
pytest -q tests/test_execution_optimizer_limit_pushdown.py                     # 28 passed
```

`ruff`, `black` and `pydoclint` at the pre-commit pins are clean;
`pyrefly`
reports the same 60 pre-existing errors as master.

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.

2 participants