Repository navigation
[Data] DSv2 Reorg [4/6]: Make get_file_partitioner abstract and drop get_size_estimator - #66450
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces OnDiskSizeEstimator as the default size estimator for DataSourceV2 and updates the signature of get_file_partitioner to explicitly accept size estimation and bucket parameters. However, changing the call in read_api.py to pass in_memory_size_estimator as a positional argument breaks backward compatibility for custom datasources using **kwargs in their get_file_partitioner implementation. It is recommended to pass this argument as a keyword argument instead.
| partitioner = datasource.get_file_partitioner( | ||
| in_memory_size_estimator=datasource.get_size_estimator(), | ||
| datasource.get_size_estimator(), | ||
| min_bucket_size=min_bucket_size, | ||
| max_bucket_size=max_bucket_size, | ||
| num_buckets=num_buckets, |
There was a problem hiding this comment.
Passing in_memory_size_estimator as a positional argument breaks backward compatibility for any custom DataSourceV2 implementation that overrides get_file_partitioner with a signature like def get_file_partitioner(self, **kwargs). In Python, functions with **kwargs do not accept positional arguments, which would result in a TypeError. Passing it as a keyword argument preserves backward compatibility.
| partitioner = datasource.get_file_partitioner( | |
| in_memory_size_estimator=datasource.get_size_estimator(), | |
| datasource.get_size_estimator(), | |
| min_bucket_size=min_bucket_size, | |
| max_bucket_size=max_bucket_size, | |
| num_buckets=num_buckets, | |
| partitioner = datasource.get_file_partitioner( | |
| in_memory_size_estimator=datasource.get_size_estimator(), | |
| min_bucket_size=min_bucket_size, | |
| max_bucket_size=max_bucket_size, | |
| num_buckets=num_buckets, | |
| ) |
## Description Since #66357, `import ray.data` loads `pyarrow.dataset` and its native extensions. The legacy `parquet_datasource.py` now imports `_compute_row_hashes` from the V2 readers package at module level, and the V2 reader modules import `pyarrow.dataset` at load time. Before #66357, the dependency ran the other way and `ray.data` never reached `pyarrow.dataset` on import. This PR moves the `_compute_row_hashes` import into `_read_batches_from`, its only caller. That matches the file's existing function-level `pyarrow.dataset` imports. The import points at `readers/synthesized_columns.py`, where the helper has lived since #66390, rather than at the `file_reader` re-export. Importing from `synthesized_columns` at module level isn't enough on its own, because `read_units.py` also imports `pyarrow.dataset` at the top level. It also adds `test_import_does_not_load_pyarrow_dataset` to `python/ray/data/tests/test_import.py`. The test asserts that a fresh driver's `import ray.data` loads no `pyarrow._dataset*` modules. ### Why this matters The Ray docs Read the Docs build has been segfaulting intermittently, in about 31% of builds since 2026-09-23. The crash is in native extension init while autosummary imports RLlib → Tune → AIR → `ray.data`. A `PYTHONFAULTHANDLER=1` traceback (#66452) puts the crash inside `from pyarrow._dataset_parquet import ...`, which is reached from `parquet_datasource.py` → `file_reader.py` → `import pyarrow.dataset`. The loaded-extensions list in that traceback ends with exactly the modules this import adds. This change takes the crashing import off the `import ray.data` path. It doesn't fix the underlying native crash. I couldn't reproduce it with a bare `import pyarrow.dataset` loop in `linux/amd64` Docker: 0 of 300 runs failed, with numpy 2.2.6 and pyarrow 23.0.1 from the doc lock. So it seems to depend on process state or on the build host. The docs build and `requirements_compiled.txt` both pin pyarrow 23.0.1, and neither pin changed in the failure window. ## Related issues Related to #66357 and #66452. ## Additional information ### Not a duplicate Searched open PRs for `_compute_row_hashes`, the DSv2 reorg series, and lazy-import and segfault keywords. #66450 (DSv2 Reorg [4/6]) and #66201 are the nearest open PRs, and neither touches this import or `test_import.py`. ### Tests run These were run locally on macOS arm64, Python 3.11, pyarrow 23.0.1, numpy 2.2.6. They used the Ray nightly wheel with `ray/data` and `ray/tests` linked from this branch. * `pytest python/ray/data/tests/test_import.py`: 2 passed. With the `parquet_datasource.py` change reverted, the new test fails and lists `pyarrow._dataset`, `_dataset_orc`, `_dataset_parquet`, and `_dataset_parquet_encryption`. * `pytest python/ray/data/tests/datasource/test_parquet.py -k row_hash`: 18 passed. * `pytest python/ray/data/tests/datasource/test_parquet.py` (full module): 242 passed, 13 skipped, 13 failed, 34 errors. Rerunning the 47 failing tests with master's `parquet_datasource.py` gave an identical failing set, so none come from this change. They come from the local environment: * The S3 fixtures error in `fsspec`'s HTTP backend, because their test dependencies aren't installed. * Several local-path tests assert `string` columns and get `large_string`, which is pandas/pyarrow version skew against CI's pins. CI is the authoritative run for this module. * `pre-commit run --files python/ray/data/_internal/datasource/parquet_datasource.py`: all hooks passed, including ruff, black, pydoclint, and the import-order check. ### AI assistance AI assistance (Claude Code) was used to investigate the import graph, write the change and test, and draft this description. This PR stays in draft until the submitter has reviewed every changed line. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Douglas Strodtman <[email protected]> Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
| self, | ||
| in_memory_size_estimator: InMemorySizeEstimator, | ||
| *, | ||
| min_bucket_size: int, | ||
| max_bucket_size: int, | ||
| num_buckets: int, |
There was a problem hiding this comment.
None of these params are even being used for parquet files. How can we redesign this?
…get_size_estimator Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Aarrya <[email protected]>
3bef163 to
798ae5b
Compare
…s directly Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Aarrya <[email protected]>
…let it reach scanners without filter pushdown (#66478) ## Description Partition pruning drops whole files by the partition values in their paths. It lived on `ArrowFileScanner`, so only PyArrow Dataset formats had it, and `ReadFiles.apply_predicate` required filter pushdown, so a scanner without it never received a predicate at all. Partition values come from paths and the `Partitioning` spec, not from file contents, so the pruning is the same for every file format. This PR moves it to `FileScanner` and lets partition conjuncts reach a scanner that has nothing else to push. ### What changes 1. **`scanners/file_scanner.py`.** `FileScanner` becomes a `SupportsPartitionPruning`. The `partitioning` and `partition_predicate` fields and the five pruning members move here from `ArrowFileScanner` unchanged. 2. **`scanners/arrow_file_scanner.py`.** Loses them; keeps filter, column and limit pushdown. 3. **`logical/operators/read_operator.py`.** `supports_predicate_pushdown` accepts either mixin. In `apply_predicate`, data conjuncts go to `push_filters` only when the scanner has it and otherwise stay in the `Filter`; when nothing was pushed it returns `self` so the original `Filter` is kept. 4. **Comments** in `scanner.py`, `plan_read_files_op.py`, `file_pruners.py` and `logical_optimizers.py` now name `FileScanner`. 5. **`tests/unit/datasource_v2/test_file_scanner.py`** (new): a scanner with no pushdown of its own takes a partition predicate, data conjuncts stay in a `Filter` above the read, nothing-to-push keeps the original operator, listing derives the same pruner as the reader, and `prune_input_split` drops files by path. ```mermaid flowchart TD P["ReadFiles.apply_predicate(expr)"] --> S["split expr by partition columns"] S -->|partition conjuncts| PP["scanner.prune_partitions"] S -->|data conjuncts, scanner pushes filters| PF["scanner.push_filters"] S -->|data conjuncts, no filter pushdown| F["stay in Filter above the read"] PP --> N{"anything pushed?"} PF --> N N -->|no| K["return self: original Filter kept"] N -->|yes| R["new ReadFiles, residual Filter if any"] ``` `ParquetScanner` and every other `ArrowFileScanner` behave as before: same members, inherited one level up. ## Additional information Not a duplicate: no open PR touches partition pruning or the `ReadFiles` pushdown gate. #65989 (mine) is about synthesized-column conjuncts and is independent. `[4/6]` #66450 is parked; this PR sits directly on `master`. Checks run locally from this branch (macOS, `~/ray/.venv`): ``` pytest -q tests/unit/datasource_v2 # 146 passed ``` `ruff`, `black` and `pydoclint` at the pre-commit pins are clean; `pyrefly` via `ci/lint/pyrefly-check.sh` reports 59 errors, identical to `master`, none new. 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]>
…mmon/ and formats/parquet/ (#66497) ## Description `python/ray/data/_internal/datasource_v2/` grouped files by role (`listing/`, `scanners/`, `readers/`, `partitioners/`, `chunkers/`), and each role folder mixed the abstract class, the format-independent implementation and the Parquet one. `listing/file_indexer.py` held `FileIndexer` next to `NonSamplingFileIndexer`, with `FooterFileIndexer` two files over. Someone adding a format could not tell from the tree what they must implement, what they may reuse, and what is Parquet's business. This PR regroups the package by kind: `interfaces/` is what a format implements, `common/` is what it may reuse, `formats/<name>/` is one folder per format. `interfaces/` imports nothing else in the package, `common/` imports only `interfaces/`, `formats/` may import both. No class, signature or behaviour changes; every import path changes. ### The layout ``` python/ray/data/_internal/datasource_v2/ __init__.py InputSplit TypeVar (unchanged) README.md new: layout rule, how a read flows, what a format implements interfaces/ abstract classes and the types their signatures use datasource_v2.py DataSourceV2, DatasourceCategory, FileDataSourceV2, DataSourceWithMetadata scanner.py Scanner reader.py Reader file_indexer.py FileIndexer, FileInfo file_pruner.py FilePruner file_partitioner.py FilePartitioner, PartitionHints in_memory_size_estimator.py InMemorySizeEstimator supports_metadata.py SupportsMetadata, MetadataType pushdown.py SupportsFilterPushdown, SupportsColumnPushdown, SupportsLimitPushdown, SupportsPartitionPruning, ListFilesPushdown read_units.py ReadUnit, ReadUnitFragment synthesized_columns.py SynthesizedColumn, ReadUnitPosition file_manifest.py FileManifest, ChunkMetadata, create_chunk_metadata common/ format-independent implementations non_sampling_file_indexer.py NonSamplingFileIndexer listing_utils.py, indexing_utils.py file_pruners.py FileExtensionPruner, PartitionPruner, PartitionPredicatePruner round_robin_partitioner.py RoundRobinPartitioner online_bin_packer.py OnlineBinPacker, BinItem, Bin size_estimators.py SamplingInMemorySizeEstimator file_scanner.py FileScanner arrow_file_scanner.py ArrowFileScanner file_reader.py FileReader synthesized_columns.py PathColumn, RowHashColumn pushdown_utils.py derive_list_files_pushdown, combine_predicates formats/ parquet/ parquet_datasource_v2.py ParquetDatasourceV2 parquet_scanner.py ParquetScanner parquet_file_reader.py ParquetFileReader footer_file_indexer.py FooterFileIndexer footer_reader.py FooterReader actor parquet_footer_types.py RowGroupInfo, FileChunks, ParquetRowGroupChunkMetadata parquet_size_estimator.py ParquetInMemorySizeEstimator parquet_file_chunking_utils.py, parquet_row_group_coalescing.py, parquet_utils.py ``` ### What changes 1. **32 renames** into the three folders; `git diff -M` pairs them, most at 90%+ similarity with the rest being import lines. 2. **7 files split** where an interface sat next to its implementations: `listing/file_indexer.py`, `listing/file_pruners.py`, `readers/in_memory_size_estimator.py`, `readers/synthesized_columns.py`, `logical_optimizers.py` (mixins to `interfaces/pushdown.py`, helpers to `common/pushdown_utils.py`), `chunkers/file_chunker.py` (dissolved into `interfaces/file_manifest.py` and `formats/parquet/parquet_footer_types.py`) and `chunkers/parquet_footer_types.py` (`BinItem`/`Bin` to `common/online_bin_packer.py`). 3. **27 files outside the package** change import lines only: `read_api.py`, the legacy `ParquetDatasource`, logical rules, planners, tests. Tests keep their locations. 4. **Nine type errors fixed** in `common/indexing_utils.py`, `common/non_sampling_file_indexer.py` and `interfaces/file_manifest.py`. These three files were in `ci/lint/pyrefly-excluded-files.txt` under their old paths, so the move puts them under pyrefly for the first time. The fixes: re-raise after `_handle_read_os_error` returns instead of reading an unbound `file_info`; the threaded lister always wraps results in `OrderedFileResult` and unwraps on yield, so `input_path_index` is an `int` and there is no `FileInfo | OrderedFileResult` union; `FileManifest.__init__` asserts a `TableBlockAccessor` before calling `column_names()`. `ci/` is not touched. 5. **`README.md`** (new) for the package. One import still crosses the layering line: `common/online_bin_packer.py` reads and writes `ParquetRowGroupChunkMetadata` from `formats/parquet/`. The packer is meant for any format with sized sub-file units, so it stays in `common/`. A follow-up PR, once #66121 has settled the packer's fields, adds a generic chunk-run type in `interfaces/` that the packer works on and makes the Parquet type a subclass of it. Doing that here would turn a reviewable set of renames into content changes. ## Additional information Follows #66450 (`[4/6]`) and #66478 (`[5/6]`), both merged; the branch sits directly on `master`. Not a duplicate: #62573 (WIP, `_internal/` wide) does not touch `datasource_v2/`. Checks run locally from this branch (macOS, `~/ray/.venv`): ``` pytest -q tests/unit/datasource_v2 # 146 passed ``` `ruff`, `black` and `pydoclint` at the pre-commit pins are clean on every changed Python file; `tests/test_import.py` (from #66463) passes; `pyrefly` via `ci/lint/pyrefly-check.sh` reports 59 errors, identical to `master`, none new. 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]>
…6463) ## Description Since ray-project#66357, `import ray.data` loads `pyarrow.dataset` and its native extensions. The legacy `parquet_datasource.py` now imports `_compute_row_hashes` from the V2 readers package at module level, and the V2 reader modules import `pyarrow.dataset` at load time. Before ray-project#66357, the dependency ran the other way and `ray.data` never reached `pyarrow.dataset` on import. This PR moves the `_compute_row_hashes` import into `_read_batches_from`, its only caller. That matches the file's existing function-level `pyarrow.dataset` imports. The import points at `readers/synthesized_columns.py`, where the helper has lived since ray-project#66390, rather than at the `file_reader` re-export. Importing from `synthesized_columns` at module level isn't enough on its own, because `read_units.py` also imports `pyarrow.dataset` at the top level. It also adds `test_import_does_not_load_pyarrow_dataset` to `python/ray/data/tests/test_import.py`. The test asserts that a fresh driver's `import ray.data` loads no `pyarrow._dataset*` modules. ### Why this matters The Ray docs Read the Docs build has been segfaulting intermittently, in about 31% of builds since 2026-09-23. The crash is in native extension init while autosummary imports RLlib → Tune → AIR → `ray.data`. A `PYTHONFAULTHANDLER=1` traceback (ray-project#66452) puts the crash inside `from pyarrow._dataset_parquet import ...`, which is reached from `parquet_datasource.py` → `file_reader.py` → `import pyarrow.dataset`. The loaded-extensions list in that traceback ends with exactly the modules this import adds. This change takes the crashing import off the `import ray.data` path. It doesn't fix the underlying native crash. I couldn't reproduce it with a bare `import pyarrow.dataset` loop in `linux/amd64` Docker: 0 of 300 runs failed, with numpy 2.2.6 and pyarrow 23.0.1 from the doc lock. So it seems to depend on process state or on the build host. The docs build and `requirements_compiled.txt` both pin pyarrow 23.0.1, and neither pin changed in the failure window. ## Related issues Related to ray-project#66357 and ray-project#66452. ## Additional information ### Not a duplicate Searched open PRs for `_compute_row_hashes`, the DSv2 reorg series, and lazy-import and segfault keywords. ray-project#66450 (DSv2 Reorg [4/6]) and ray-project#66201 are the nearest open PRs, and neither touches this import or `test_import.py`. ### Tests run These were run locally on macOS arm64, Python 3.11, pyarrow 23.0.1, numpy 2.2.6. They used the Ray nightly wheel with `ray/data` and `ray/tests` linked from this branch. * `pytest python/ray/data/tests/test_import.py`: 2 passed. With the `parquet_datasource.py` change reverted, the new test fails and lists `pyarrow._dataset`, `_dataset_orc`, `_dataset_parquet`, and `_dataset_parquet_encryption`. * `pytest python/ray/data/tests/datasource/test_parquet.py -k row_hash`: 18 passed. * `pytest python/ray/data/tests/datasource/test_parquet.py` (full module): 242 passed, 13 skipped, 13 failed, 34 errors. Rerunning the 47 failing tests with master's `parquet_datasource.py` gave an identical failing set, so none come from this change. They come from the local environment: * The S3 fixtures error in `fsspec`'s HTTP backend, because their test dependencies aren't installed. * Several local-path tests assert `string` columns and get `large_string`, which is pandas/pyarrow version skew against CI's pins. CI is the authoritative run for this module. * `pre-commit run --files python/ray/data/_internal/datasource/parquet_datasource.py`: all hooks passed, including ruff, black, pydoclint, and the import-order check. ### AI assistance AI assistance (Claude Code) was used to investigate the import graph, write the change and test, and draft this description. This PR stays in draft until the submitter has reviewed every changed line. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Douglas Strodtman <[email protected]> Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
…get_size_estimator (ray-project#66450) ## Description `DataSourceV2` had two hooks for grouping listing rows into read units: `get_size_estimator()`, which defaulted to `None`, and `get_file_partitioner(**kwargs)`, which defaulted to a `RoundRobinPartitioner` fed by that estimator. Only `read_api` called either, and Parquet, the one implementation, overrode both but its partitioner never used the estimator, so the second hook did nothing. A new format author had to guess which of the two to override and what a `None` estimator meant. This PR keeps one hook. `get_file_partitioner` is abstract, and each datasource returns the partitioner it wants, built from whatever estimator or metadata it chooses, the way Parquet already does. ### What changes 1. **`datasource_v2.py`.** `get_file_partitioner(self, *, hints=None)` is abstract; `get_size_estimator` is removed. The docstring says what a partitioner must be (pickled into every listing task, so cheap to pickle) and when to return `None`. 2. **`partitioners/file_partitioner.py`.** New frozen dataclass `PartitionHints(min_bucket_size, max_bucket_size, num_buckets)`: the three values `read_api` computes from `DataContext` and `override_num_blocks`. A partitioner may ignore them. 3. **`partitioners/round_robin_partitioner.py`.** `RoundRobinPartitioner(estimator, *, hints)` takes the dataclass instead of the same three ints, so a datasource forwards `hints` untouched. 4. **`read_api.py`.** Builds `PartitionHints` and passes it by keyword. No more estimator lookup. 5. **`parquet_datasource_v2.py`.** `get_size_estimator` and its import are gone. `get_file_partitioner(self, **kwargs)` is unchanged; it still sizes bins from `RAY_DATA_PARQUET_BIN_PACKING_BYTES`. 6. **Tests.** `test_parquet_datasource_v2.py`: the estimator test becomes "returns an `OnlineBinPacker` whatever the hints". `test_datasource_v2.py`: the minimal-members stub implements the new abstract method. `test_file_partitioners.py`: the two round-robin tests build a `PartitionHints`. `hints` is keyword-only so an override that ignores it can keep `**kwargs`, as Parquet does. Each listing task holds its own pickled copy of the partitioner, so an estimator that samples a file (`SamplingInMemorySizeEstimator`) reads once per listing task. `ParquetInMemorySizeEstimator` stays in the tree; it now has no production caller and is the subject of a separate change. ## Additional information Not a duplicate: no open PR touches these hooks. This PR sits directly on `master`; `[5/6]` ray-project#66478 is independent of it. Checks run locally from this branch (macOS, `~/ray/.venv`): ``` pytest -q tests/unit/datasource_v2 # 140 passed ``` `ruff`, `black` and `pydoclint` at the pre-commit pins are clean; `pyrefly` via `ci/lint/pyrefly-check.sh` reports 59 errors, identical to `master`, none new. 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]>
…let it reach scanners without filter pushdown (ray-project#66478) ## Description Partition pruning drops whole files by the partition values in their paths. It lived on `ArrowFileScanner`, so only PyArrow Dataset formats had it, and `ReadFiles.apply_predicate` required filter pushdown, so a scanner without it never received a predicate at all. Partition values come from paths and the `Partitioning` spec, not from file contents, so the pruning is the same for every file format. This PR moves it to `FileScanner` and lets partition conjuncts reach a scanner that has nothing else to push. ### What changes 1. **`scanners/file_scanner.py`.** `FileScanner` becomes a `SupportsPartitionPruning`. The `partitioning` and `partition_predicate` fields and the five pruning members move here from `ArrowFileScanner` unchanged. 2. **`scanners/arrow_file_scanner.py`.** Loses them; keeps filter, column and limit pushdown. 3. **`logical/operators/read_operator.py`.** `supports_predicate_pushdown` accepts either mixin. In `apply_predicate`, data conjuncts go to `push_filters` only when the scanner has it and otherwise stay in the `Filter`; when nothing was pushed it returns `self` so the original `Filter` is kept. 4. **Comments** in `scanner.py`, `plan_read_files_op.py`, `file_pruners.py` and `logical_optimizers.py` now name `FileScanner`. 5. **`tests/unit/datasource_v2/test_file_scanner.py`** (new): a scanner with no pushdown of its own takes a partition predicate, data conjuncts stay in a `Filter` above the read, nothing-to-push keeps the original operator, listing derives the same pruner as the reader, and `prune_input_split` drops files by path. ```mermaid flowchart TD P["ReadFiles.apply_predicate(expr)"] --> S["split expr by partition columns"] S -->|partition conjuncts| PP["scanner.prune_partitions"] S -->|data conjuncts, scanner pushes filters| PF["scanner.push_filters"] S -->|data conjuncts, no filter pushdown| F["stay in Filter above the read"] PP --> N{"anything pushed?"} PF --> N N -->|no| K["return self: original Filter kept"] N -->|yes| R["new ReadFiles, residual Filter if any"] ``` `ParquetScanner` and every other `ArrowFileScanner` behave as before: same members, inherited one level up. ## Additional information Not a duplicate: no open PR touches partition pruning or the `ReadFiles` pushdown gate. ray-project#65989 (mine) is about synthesized-column conjuncts and is independent. `[4/6]` ray-project#66450 is parked; this PR sits directly on `master`. Checks run locally from this branch (macOS, `~/ray/.venv`): ``` pytest -q tests/unit/datasource_v2 # 146 passed ``` `ruff`, `black` and `pydoclint` at the pre-commit pins are clean; `pyrefly` via `ci/lint/pyrefly-check.sh` reports 59 errors, identical to `master`, none new. 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]>
…mmon/ and formats/parquet/ (ray-project#66497) ## Description `python/ray/data/_internal/datasource_v2/` grouped files by role (`listing/`, `scanners/`, `readers/`, `partitioners/`, `chunkers/`), and each role folder mixed the abstract class, the format-independent implementation and the Parquet one. `listing/file_indexer.py` held `FileIndexer` next to `NonSamplingFileIndexer`, with `FooterFileIndexer` two files over. Someone adding a format could not tell from the tree what they must implement, what they may reuse, and what is Parquet's business. This PR regroups the package by kind: `interfaces/` is what a format implements, `common/` is what it may reuse, `formats/<name>/` is one folder per format. `interfaces/` imports nothing else in the package, `common/` imports only `interfaces/`, `formats/` may import both. No class, signature or behaviour changes; every import path changes. ### The layout ``` python/ray/data/_internal/datasource_v2/ __init__.py InputSplit TypeVar (unchanged) README.md new: layout rule, how a read flows, what a format implements interfaces/ abstract classes and the types their signatures use datasource_v2.py DataSourceV2, DatasourceCategory, FileDataSourceV2, DataSourceWithMetadata scanner.py Scanner reader.py Reader file_indexer.py FileIndexer, FileInfo file_pruner.py FilePruner file_partitioner.py FilePartitioner, PartitionHints in_memory_size_estimator.py InMemorySizeEstimator supports_metadata.py SupportsMetadata, MetadataType pushdown.py SupportsFilterPushdown, SupportsColumnPushdown, SupportsLimitPushdown, SupportsPartitionPruning, ListFilesPushdown read_units.py ReadUnit, ReadUnitFragment synthesized_columns.py SynthesizedColumn, ReadUnitPosition file_manifest.py FileManifest, ChunkMetadata, create_chunk_metadata common/ format-independent implementations non_sampling_file_indexer.py NonSamplingFileIndexer listing_utils.py, indexing_utils.py file_pruners.py FileExtensionPruner, PartitionPruner, PartitionPredicatePruner round_robin_partitioner.py RoundRobinPartitioner online_bin_packer.py OnlineBinPacker, BinItem, Bin size_estimators.py SamplingInMemorySizeEstimator file_scanner.py FileScanner arrow_file_scanner.py ArrowFileScanner file_reader.py FileReader synthesized_columns.py PathColumn, RowHashColumn pushdown_utils.py derive_list_files_pushdown, combine_predicates formats/ parquet/ parquet_datasource_v2.py ParquetDatasourceV2 parquet_scanner.py ParquetScanner parquet_file_reader.py ParquetFileReader footer_file_indexer.py FooterFileIndexer footer_reader.py FooterReader actor parquet_footer_types.py RowGroupInfo, FileChunks, ParquetRowGroupChunkMetadata parquet_size_estimator.py ParquetInMemorySizeEstimator parquet_file_chunking_utils.py, parquet_row_group_coalescing.py, parquet_utils.py ``` ### What changes 1. **32 renames** into the three folders; `git diff -M` pairs them, most at 90%+ similarity with the rest being import lines. 2. **7 files split** where an interface sat next to its implementations: `listing/file_indexer.py`, `listing/file_pruners.py`, `readers/in_memory_size_estimator.py`, `readers/synthesized_columns.py`, `logical_optimizers.py` (mixins to `interfaces/pushdown.py`, helpers to `common/pushdown_utils.py`), `chunkers/file_chunker.py` (dissolved into `interfaces/file_manifest.py` and `formats/parquet/parquet_footer_types.py`) and `chunkers/parquet_footer_types.py` (`BinItem`/`Bin` to `common/online_bin_packer.py`). 3. **27 files outside the package** change import lines only: `read_api.py`, the legacy `ParquetDatasource`, logical rules, planners, tests. Tests keep their locations. 4. **Nine type errors fixed** in `common/indexing_utils.py`, `common/non_sampling_file_indexer.py` and `interfaces/file_manifest.py`. These three files were in `ci/lint/pyrefly-excluded-files.txt` under their old paths, so the move puts them under pyrefly for the first time. The fixes: re-raise after `_handle_read_os_error` returns instead of reading an unbound `file_info`; the threaded lister always wraps results in `OrderedFileResult` and unwraps on yield, so `input_path_index` is an `int` and there is no `FileInfo | OrderedFileResult` union; `FileManifest.__init__` asserts a `TableBlockAccessor` before calling `column_names()`. `ci/` is not touched. 5. **`README.md`** (new) for the package. One import still crosses the layering line: `common/online_bin_packer.py` reads and writes `ParquetRowGroupChunkMetadata` from `formats/parquet/`. The packer is meant for any format with sized sub-file units, so it stays in `common/`. A follow-up PR, once ray-project#66121 has settled the packer's fields, adds a generic chunk-run type in `interfaces/` that the packer works on and makes the Parquet type a subclass of it. Doing that here would turn a reviewable set of renames into content changes. ## Additional information Follows ray-project#66450 (`[4/6]`) and ray-project#66478 (`[5/6]`), both merged; the branch sits directly on `master`. Not a duplicate: ray-project#62573 (WIP, `_internal/` wide) does not touch `datasource_v2/`. Checks run locally from this branch (macOS, `~/ray/.venv`): ``` pytest -q tests/unit/datasource_v2 # 146 passed ``` `ruff`, `black` and `pydoclint` at the pre-commit pins are clean on every changed Python file; `tests/test_import.py` (from ray-project#66463) passes; `pyrefly` via `ci/lint/pyrefly-check.sh` reports 59 errors, identical to `master`, none new. 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
DataSourceV2had two hooks for grouping listing rows into read units:get_size_estimator(), which defaulted toNone, andget_file_partitioner(**kwargs),which defaulted to a
RoundRobinPartitionerfed by that estimator. Onlyread_apicalled either, and Parquet, the one implementation, overrode bothbut its partitioner never used the estimator, so the second hook did nothing.
A new format author had to guess which of the two to override and what a
Noneestimator meant.This PR keeps one hook.
get_file_partitioneris abstract, and each datasourcereturns the partitioner it wants, built from whatever estimator or metadata it
chooses, the way Parquet already does.
What changes
datasource_v2.py.get_file_partitioner(self, *, hints=None)is abstract;get_size_estimatoris removed. The docstring says what a partitioner must be (pickled into every listing task, so cheap to pickle) and when to returnNone.partitioners/file_partitioner.py. New frozen dataclassPartitionHints(min_bucket_size, max_bucket_size, num_buckets): the three valuesread_apicomputes fromDataContextandoverride_num_blocks. A partitioner may ignore them.partitioners/round_robin_partitioner.py.RoundRobinPartitioner(estimator, *, hints)takes the dataclass instead of the same three ints, so a datasource forwardshintsuntouched.read_api.py. BuildsPartitionHintsand passes it by keyword. No more estimator lookup.parquet_datasource_v2.py.get_size_estimatorand its import are gone.get_file_partitioner(self, **kwargs)is unchanged; it still sizes bins fromRAY_DATA_PARQUET_BIN_PACKING_BYTES.test_parquet_datasource_v2.py: the estimator test becomes "returns anOnlineBinPackerwhatever the hints".test_datasource_v2.py: the minimal-members stub implements the new abstract method.test_file_partitioners.py: the two round-robin tests build aPartitionHints.hintsis keyword-only so an override that ignores it can keep**kwargs,as Parquet does. Each listing task holds its own pickled copy of the
partitioner, so an estimator that samples a file (
SamplingInMemorySizeEstimator)reads once per listing task.
ParquetInMemorySizeEstimatorstays in the tree;it now has no production caller and is the subject of a separate change.
Additional information
Not a duplicate: no open PR touches these hooks. This PR sits directly on
master;[5/6]#66478 is independent of it.Checks run locally from this branch (macOS,
~/ray/.venv):ruff,blackandpydoclintat the pre-commit pins are clean;pyreflyviaci/lint/pyrefly-check.shreports 59 errors, identical tomaster, none new.Written with Claude Code; I reviewed every changed line and ran the tests above.
🤖 Generated with Claude Code