Repository navigation
[Data] DSv2 Reorg [1.5/6]: Add FileDataSourceV2 and DataSourceWithMetadata as the two bases every datasource extends - #66312
Conversation
Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Aarrya <[email protected]>
…arquet datasources Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Aarrya <[email protected]>
…s docstring Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Aarrya <[email protected]>
… as the two bases every datasource extends Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Aarrya <[email protected]>
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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``. | |||
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
it lands in PR 5/6
| @property | ||
| def file_extensions(self) -> Optional[List[str]]: | ||
| """File extensions to keep while listing; ``None`` keeps every file.""" | ||
| return None |
There was a problem hiding this comment.
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.
| @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 |
There was a problem hiding this comment.
reason for keeping it abstract: adding a datasource forces the question
…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]): |
There was a problem hiding this comment.
Why is this called TableDataSourceV2?
There was a problem hiding this comment.
CatalogDataSourceV2 would make more sense
There was a problem hiding this comment.
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]>
FileDataSourceV2 and DataSourceWithMetadata as the two bases every datasource extends
… 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]>
…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]>
…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]>
… 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]>
Description
Sits between
[1/6](#66066) and[2/6]in the DSv2 Reorg series, stackedon #66066; the diff shows both until that one merges.
DataSourceV2asks every datasource for a PyArrowfilesystem, a list offile_extensionsand a fileshuffle. Those only mean something when Raywalks a filesystem to find the files. A source whose indexer already knows its
data, such as Iceberg or a database, had to return
Nonefor all three just tosatisfy 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 SQLChanges
FileDataSourceV2:filesystemabstract and neverNone;file_extensionsandshuffledefaultNone. The three members leavethe base class.
ParquetDatasourceV2extends it.DataSourceWithMetadata:schema_needs_file_sampledefaults toFalse, sincethe schema comes from the same metadata as the listing.
_read_datasource_v2reads the three file members from aFileDataSourceV2, passesNonefor aDataSourceWithMetadata, and rejects aclass that extends the base directly.
tests/unit/datasource_v2/test_datasource_v2.py.Additional information
Not a duplicate: no open PR changes the
DataSourceV2class hierarchy. Theopen CSV migration (#65743) is a plain file format and would extend
FileDataSourceV2after a rebase.Tests run locally from this branch (macOS,
~/ray/.venv), frompython/ray/data:The 34 errors are moto
s3_fsfixture setup errors (moto_servernot onPATH), identical on master.
ruff,blackandpydoclintat the pre-commitpins are clean;
pyreflyreports the same 61 pre-existing errors as the basecommit.
Written with Claude Code; I reviewed every changed line and ran the tests above.
🤖 Generated with Claude Code