Repository navigation
[Data] [6/11] Add FooterFileIndexer behind an opt-in flag, with bin packing as a partitioner - #65596
Conversation
Parquet V2 chunks files blindly: `ParquetFileChunker` splits each file by `ceil(file_size / 1 GiB)` without reading the footer, and the partitioner bin-packs those guesses with a fixed encoding-ratio estimate. Bin sizes are inaccurate because the compression ratio is unknown until the footer is read, and there is no row-group skipping. `FooterFileIndexer` reads each file's footer on the `FooterReader` actor pool and packs its row groups with `OnlineBinPacker`, so read units are row-group-accurate instead of size-estimated. It reports `yields_read_units`, so `ListFiles` skips the size-balancing partitioner and lists in one task (the packer needs the whole stream to pack globally), and it consumes the pushed predicate / limit / projection to skip row groups, stop listing early, and size bins over projected columns only. Gated on `RAY_DATA_PARQUET_ENABLE_FOOTER_INDEXER` (default off) so this lands with no behavior change. Both paths coexist: the reader dispatches on the manifest's metadata type, and `_fragments_from_row_group_ids` is added alongside the size-based helper. Flipping the default and deleting the old path are separate steps. Reader-side: batch size is now estimated from the footer stats the manifest already carries, avoiding a second footer read per task. Also re-reads every footer env knob in `__init__`. Previously only `NUM_ACTORS` and `BIN_PACKING_BYTES` were, so `monkeypatch.setenv` and release-test overrides silently did nothing for the rest. Signed-off-by: Goutam <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request introduces an opt-in footer-based indexing strategy for Parquet files in Ray Data via the new FooterFileIndexer. This strategy leverages a pool of FooterReader actors to read file footers and bin-pack row groups, enabling row-group-accurate read units and push-downs (predicates, limits, and projections) directly during listing. The feedback is highly constructive and identifies several key improvements: resolving a potential actor leak if initialization fails, optimizing performance by avoiding repeated DataContext.get_current() lookups in loops, preventing a potential ZeroDivisionError if the actor count is configured to zero or negative, and adding warning logs when files with unknown sizes are skipped to prevent silent data loss.
| def _with_io_retry(f: Callable[[], R], description: str) -> R: | ||
| """Run ``f``, retrying the transient IO errors configured on the context. | ||
|
|
||
| ``ParquetFileFragment.subset`` and ``.metadata`` both open the file to read | ||
| its footer, so on remote storage they fail with the same transient errors | ||
| (S3 timeouts, throttling) the rest of the read path already retries. | ||
| """ | ||
| from ray.data.context import DataContext | ||
|
|
||
| return call_with_retry( | ||
| f, | ||
| description=description, | ||
| match=DataContext.get_current().retried_io_errors, | ||
| ) |
There was a problem hiding this comment.
Calling DataContext.get_current() repeatedly inside a loop (via _with_io_retry in _fragments_from_row_group_ids) can introduce significant overhead due to thread-local lookups. Allowing _with_io_retry to accept pre-fetched retried_errors avoids this overhead.
def _with_io_retry(
f: Callable[[], R],
description: str,
retried_errors: Optional[List[type]] = None,
) -> R:
"""Run ``f``, retrying the transient IO errors configured on the context.
``ParquetFileFragment.subset`` and ``.metadata`` both open the file to read
its footer, so on remote storage they fail with the same transient errors
(S3 timeouts, throttling) the rest of the read path already retries.
"""
if retried_errors is None:
from ray.data.context import DataContext
retried_errors = DataContext.get_current().retried_io_errors
return call_with_retry(
f,
description=description,
match=retried_errors,
)| ids = sorted(row_group_ids) | ||
| if not ids: | ||
| return [] | ||
|
|
||
| def _subset(rg_ids: List[int]) -> pds.ParquetFileFragment: | ||
| return _with_io_retry( | ||
| lambda: fragment.subset(row_group_ids=rg_ids), | ||
| f"subset row groups {rg_ids} of {fragment.path}", | ||
| ) | ||
|
|
||
| if not per_row_group_offsets: | ||
| return [(_subset(ids), 0)] | ||
|
|
||
| metadata = _with_io_retry( | ||
| lambda: fragment.metadata, f"read Parquet footer for {fragment.path}" | ||
| ) | ||
| # Cumulative pre-filter row offset at the start of each physical row group. | ||
| prefix = [0] * (metadata.num_row_groups + 1) | ||
| for i in range(metadata.num_row_groups): | ||
| prefix[i + 1] = prefix[i] + metadata.row_group(i).num_rows | ||
| return [(_subset([rg_id]), prefix[rg_id]) for rg_id in ids] |
There was a problem hiding this comment.
Fetch retried_errors once outside the loop and pass it to _with_io_retry to avoid repeated DataContext.get_current() lookups for each row group.
ids = sorted(row_group_ids)
if not ids:
return []
from ray.data.context import DataContext
retried_errors = DataContext.get_current().retried_io_errors
def _subset(rg_ids: List[int]) -> pds.ParquetFileFragment:
return _with_io_retry(
lambda: fragment.subset(row_group_ids=rg_ids),
f"subset row groups {rg_ids} of {fragment.path}",
retried_errors=retried_errors,
)
if not per_row_group_offsets:
return [(_subset(ids), 0)]
metadata = _with_io_retry(
lambda: fragment.metadata,
f"read Parquet footer for {fragment.path}",
retried_errors=retried_errors,
)
# Cumulative pre-filter row offset at the start of each physical row group.
prefix = [0] * (metadata.num_row_groups + 1)
for i in range(metadata.num_row_groups):
prefix[i + 1] = prefix[i] + metadata.row_group(i).num_rows
return [(_subset([rg_id]), prefix[rg_id]) for rg_id in ids]| self._num_actors = env_integer( | ||
| "RAY_DATA_PARQUET_FOOTER_NUM_ACTORS", _DEFAULT_NUM_ACTORS | ||
| ) |
There was a problem hiding this comment.
| for file_info in file_infos: | ||
| if file_info.size is None: | ||
| continue |
There was a problem hiding this comment.
Silently skipping files with an unknown size (None) can lead to silent data loss or unexpected correctness issues, as the user will not be notified that some files were omitted. Log a warning to make this visible.
if file_info.size is None:
logger.warning(
"Skipping file %s because its size is unknown (None). "
"Parquet footer reading requires a known file size.",
file_info.path,
)
continue0f7b2cc to
ceb8e60
Compare
Three fixes to the opt-in footer read path, which are entangled and so land together. `skip_paths`: FooterFileIndexer was constructed without it, so `read_parquet(..., skip_paths=...)` silently did nothing on this path -- excluded files were read, and a missing path named only in `skip_paths` could fail the listing instead of being ignored. Bin packing: the indexer packed row groups into bins inline and advertised `produces_partitioned_manifests`, which told the planner to skip the partitioner stage. That made `shuffle="files"` collapse the dataset into a single read task, because `shuffle_files` concatenates every sealed bin into one manifest block and nothing downstream was left to re-split it. Packing moves into OnlineBinPacker as a real FilePartitioner running after the shuffle: listing only discovers work, emitting one manifest row per row-group run with that run's exact footer stats, and the packer owns grouping runs into read units and splitting them at row-group boundaries. `produces_partitioned_manifests` gives way to `FilePartitioner.requires_global_input`. `count()` pushdown: PushdownCountFiles forced whole-file listing by overwriting the indexer's `_file_chunker`, but FooterFileIndexer overrides `list_files` outright and ignores its chunker, so the swap was a silent no-op. It now replaces the indexer via `as_whole_file_indexer()`. This is what makes the packing change safe -- once listing emits a row per row-group run, `read_metadata` returns the whole file's row count for each one, so a 4-row-group file counts 4x. Also replaces a hard `assert isinstance` with a debug log and bail-out, so a third-party indexer falls back to the regular read path instead of crashing the optimizer. Bin sizing moves to the partitioner with the packing, which surfaced that `get_file_partitioner` never forwarded RAY_DATA_PARQUET_BIN_PACKING_MAX_SHARED_OPEN_BINS at all; it is wired through now. Signed-off-by: Goutam <[email protected]> Co-authored-by: Cursor <[email protected]> Signed-off-by: Goutam <[email protected]> Co-authored-by: Cursor <[email protected]>
ceb8e60 to
7021dd5
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.
Reviewed by Cursor Bugbot for commit 7021dd5. Configure here.
Signed-off-by: Goutam <[email protected]>
| a footer-reading one. | ||
| """ | ||
| items: List[BinItem] = [] | ||
| for path, file_size, md in zip( |
There was a problem hiding this comment.
instead of md using metadata
ayushk7102
left a comment
There was a problem hiding this comment.
I think we should be explicit to users about the internal knobs added in this PR because they can have an impact on performance and are highly dependent on the workload.
We should try to:
- log the values of these knobs for e.g. for _footer_batch_size every time we estimate something based on these knobs
- point users to the env variables that they can change to tune these knobs, via the docs and maybe also via logging everytime we estimate something based on these knobs
| # Every knob is re-read here rather than taken from the module-level | ||
| # constant, so ``monkeypatch.setenv`` and release-test env overrides work | ||
| # after this module has already been imported. An explicit ctor argument | ||
| # still wins over the environment. |
There was a problem hiding this comment.
Can we look at moving some of these knobs to constructor params instead? I think it'll make for easier testing rather than having to monkeypatch the environment, and also for better UX.
I think it's preferable to move things that people will change while performance/memory tuning to constructor params, that way we can more systematically change them from the code rather than by setting an env.
| rg_sizes=(), | ||
| rg_rows=(), |
There was a problem hiding this comment.
minor nit: Since binning already does the partitioning these two variables are not needed anymore. Could we eliminate these variables if they're no longer needed, or maybe create a new subclass BinnedChunkMetadata which is already partitioned and doesn't have these?
| first_fragment = next(dataset.get_fragments(), None) | ||
| if first_fragment is None: | ||
| return None | ||
| return _estimate_batch_size_from_metadata( | ||
| first_fragment, self._columns, self._target_block_size | ||
| ) |
There was a problem hiding this comment.
Let's drop the fallback if it's not accessible -- when is chunk ever going to be None?
There was a problem hiding this comment.
Oh we should drop it once FooterFileIndexer becomes the default in a subsequent change.
|
Discussed offline - we need to plan a refactor such that file 'discovery' is separated from 'indexing'. Currently, the implementation is coupled together for both. When shuffle is enabled, this happens at the indexing stage, and this results in poor binning due to the current bin packing logic. As an immediate next step we can move shuffle for the ParquetFileIndexer into the discovery phase, but we want to have a long term solution which might need refactoring |
Signed-off-by: Goutam <[email protected]>
Signed-off-by: Goutam <[email protected]>
…65806) ## Why Two independent throughput knobs for the Parquet read task, kept out of the footer-indexer PR because each changes behavior on its own and needs its own justification. **One reader thread per fragment, instead of capping at 4.** The cap existed because the blind `ParquetFileChunker` could put an unbounded number of row groups — and therefore fragments — in a single read task, so an uncapped thread pool was a real risk. Now that #65596 has landed, read units are bin-packed to a byte budget, so the fragment count per task is bounded by construction and the cap only serializes IO that could overlap. **Size Arrow's IO/CPU pools for the read task.** Arrow's defaults (~num cores, 8 IO threads) throttle the concurrent column/range fetches a Parquet scan issues against S3. That hurts most for row-group-scoped fragments, which is exactly what the footer path now produces. ## Flow No structural change — both are sizing knobs on the existing read path: ``` ReadFiles task ├─ pa.set_io_thread_count / set_cpu_count ← new, at reader construction └─ _read_fragment_batches └─ num_workers = len(fragments) ← was min(4, len(fragments)) ``` The sequential path still applies when `DataContext.execution_options.preserve_order` is set, unchanged. ## What changed | File | Change | | --- | --- | | `readers/file_reader.py` | Drop `_DEFAULT_NUM_THREADS` / `RAY_DATA_READ_FILES_NUM_THREADS`; `num_workers = len(fragments_with_offsets)`. Also fixes the `_read_fragment_batches` docstring, which still documented the removed env var. | | `readers/parquet_file_reader.py` | `pa.set_io_thread_count()` / `pa.set_cpu_count()` at reader construction, from `RAY_DATA_PARQUET_READER_IO_THREAD_COUNT` / `RAY_DATA_PARQUET_READER_CPU_COUNT` (default 128 each; `0` disables). | **Two things worth a careful look:** - This **removes** `RAY_DATA_READ_FILES_NUM_THREADS`. It is undocumented and internal, but anyone setting it loses the knob. - `pa.set_io_thread_count` / `set_cpu_count` mutate **process-global** Arrow state from a constructor. That is deliberate — the read task is the process — but it means a non-Parquet reader sharing the worker sees the same pools. ## Stack Step 8 of an 11-step split of #64985. - #65167 `[1/11]` ✅ · #65168 `[2/11]` ✅ · #65214 `[3/11]` ✅ · #65210 `[4/11]` ✅ · #65273 `[5/11]` ✅ - #65596 `[6/11]` ✅ — footer indexer behind the flag, which also absorbed step 7's `count()` fix and moved bin packing into a `FilePartitioner` - **this PR** `[8/11]` — unblocked by #65596: the thread cap can only come off once bins are size-bounded - #65169 `[9/11]` pin the footer actor pool to 1 in tests (open, independent) Remaining after this: release-test tuning, then flipping the default and deleting the old chunker. --------- Signed-off-by: Goutam <[email protected]>
Tunes the Data release tests for the footer path, so this PR can be validated by an actual release run rather than by unit tests alone. Carried over from the tuning measured on the original branch (ray-project#64985), with the stale parts dropped: 7 of the 33 originally-pinned entries no longer exist (the autoscaling variants removed in ray-project#65506, plus tpch_q20 / tpch_q22), and the `{{scaling}}` de-templating is unnecessary because ray-project#65506 already left those entries spelled out. 26 entries get a pin. Most hold the previous 64 MiB behaviour on tests that regressed when the fallback default moved to 128 MiB; a few go the other way (1 GiB / 1.25 GiB) for datasets whose row groups are large enough that the default produces one read task per row group. Three entries are split out of their matrices because a matrix cannot vary `byod.runtime_env` per value and their variants want different budgets: `wide_schema_pipeline_{{data_type}}` into four, and one variant each out of `iceberg_benchmark_{{mode}}` and `iter_batches_{{format}}`. Rendered test names are unchanged -- 121 before and after -- so release baselines still line up. Any entry that gains its own `runtime_env` re-lists the four DEFAULTS guards verbatim: `deep_update` overwrites lists rather than merging them, so declaring one silently drops the OOM / dead-node / object-store checks. Also drops `map_benchmark.py`'s `use_datasource_v2 = False` pin, which was there because V2 was spilling; the footer path is the read path now. These budgets were measured against the pre-decoupling design. Packing moved between stages in ray-project#65596 but the packer and its inputs did not, so the bins should be unchanged -- treat these as a starting point to confirm or correct with a release run, not as settled values. Signed-off-by: Goutam <[email protected]>
## Why The last step of the split of #64985: flip Parquet V2 to the footer read path, delete the blind one, and tune the release tests so this can be validated by a real release run. Everything it depends on has landed — footer types and the bin packer (#65210), the `FooterReader` actor pool (#65273), the indexer plus `count()` fix and packer-as-partitioner (#65596), reader IO tuning (#65806), and test env pinning (#65169). The path has been reachable behind `RAY_DATA_PARQUET_ENABLE_FOOTER_INDEXER` since #65596; this makes it the only path. ## Flow ```mermaid flowchart LR RP[read_parquet] --> FF["FooterFileIndexer<br/>+ OnlineBinPacker"] RP -.->|deleted| PC["ParquetFileChunker<br/>size-estimated chunks<br/>+ parquet_chunker_target_chunk_size"] style PC stroke-dasharray: 4 4 ``` ## What changed **The flip** — `RAY_DATA_PARQUET_ENABLE_FOOTER_INDEXER` is gone from both call sites. `_get_file_indexer()` always returns `FooterFileIndexer`; `get_file_partitioner()` always returns `OnlineBinPacker`. **The deletions** — `ParquetFileChunker`, `ParquetFileChunkMetadata`, `_calculate_row_group_range`, `_fragments_from_chunk_metadata`, and the tests covering only that path. **The config it left behind** — `DataContext.parquet_chunker_target_chunk_size` and `DEFAULT_PARQUET_CHUNKER_TARGET_CHUNK_SIZE` were read *only* by `ParquetFileChunker.__init__`, so they would otherwise stay declared and documented while doing nothing. Verified dead by grep across `.py` / `.yaml` / `.rst` / `.md`. **Reader pool defaults** — `RAY_DATA_PARQUET_READER_IO_THREAD_COUNT` 128, `RAY_DATA_PARQUET_READER_CPU_COUNT` 32. ## Release tests tuned Budgets are per-test overrides of `RAY_DATA_PARQUET_BIN_PACKING_BYTES` (uncompressed bytes of row-group data per read task; default 128 MiB). The shape of the tuning: reads over few large groups want **large** bins, because small bins shatter the read into short tasks the executor cannot dispatch fast enough and the cluster idles; shuffle-bound reads over many groups want **small** bins. Rows whose variants all share the same tuning are collapsed and marked. | release test | bin budget | other tuning | | --- | --- | --- | | `aggregate_groups_fixed_size_hash_shuffle_column02 column14` | 32 MiB | — | | `aggregate_groups_fixed_size_hash_shuffle_column08 column13 column14` | 128 MiB | — | | `aggregate_groups_fixed_size_shuffle_v2_column02 column14` | 64 MiB | — | | `aggregate_groups_fixed_size_shuffle_v2_column08 column13 column14` | 512 MiB | — | | `aggregate_groups_fixed_size_sort_shuffle_pull_based_column02 column14` | 32 MiB | — | | `aggregate_groups_fixed_size_sort_shuffle_pull_based_column08 column13 column14` | 256 MiB | — | | `count_parquet_fixed_size` | 64 MiB | — | | `cross_az_map_batches_autoscaling_iptable_failure_injection` | 1 GiB | — | | `distributed_training` | — | footer actors `20` | | `flat_map` | 64 MiB | — | | `iceberg_benchmark_overwrite` | 64 MiB | — | | `iter_batches_pyarrow` | 64 MiB | — | | `iter_torch_batches` | 64 MiB | — | | `joins_{{dataset}}_{{join_type}} *(all 4 variants)*` | 1.25 GiB | — | | `map` | 64 MiB | — | | `map_batches_fixed_size_{{compute}}_{{format}}_{{repeat_map_batches}} *(all 7 variants)*` | 1 GiB | scale-up threshold `0.6` | | `map_groups_fixed_size_{{shuffle_strategy}}_{{columns}} *(all 6 variants)*` | 1.25 GiB | — | | `mix` | — | footer actors `4` | | `random_shuffle_fixed_size` | 64 MiB | — | | `read_large_parquet_fixed_size` | 1 GiB | — | | `read_parquet_fixed_size` | 64 MiB | — | | `read_tfrecords` | 64 MiB | — | | `streaming_split` | 64 MiB | footer batch `50`, result batch `50` | | `to_tf` | 64 MiB | — | | `tpch_q1_fixed_size_{{shuffle_strategy}} *(all 2 variants)*` | 192 MiB | — | | `training_ingest_benchmark` | 64 MiB | — | | `wide_schema_pipeline_nested_structs` | 2 MiB | footer batch `1`, footer actors `21`, io threads `5000` | | `wide_schema_pipeline_objects` | 4.2 MiB | footer batch `1`, footer actors `9`, io threads `5000` | | `wide_schema_pipeline_primitives` | 256 KiB | footer batch `1`, footer actors `27`, io threads `5000` | | `wide_schema_pipeline_tensors` | 39 MiB | footer batch `1`, footer actors `22`, io threads `5000` | | `write_parquet` | 1.25 GiB | — | **Three matrices are split**, because a matrix cannot vary `byod.runtime_env` per value and their variants want different budgets: `wide_schema_pipeline_{{data_type}}` into four entries, and one variant each out of `iceberg_benchmark_{{mode}}` and `iter_batches_{{format}}`. `aggregate_groups` keeps its matrix and carries the budget as a matrix dimension with explicit adjustments. **Rendered test names are unchanged — 121 before and after** — so release baselines still line up. **Not carried over** from the original branch: 7 previously-pinned entries no longer exist — the autoscaling variants removed in #65506, plus `tpch_q20` and `tpch_q22`. Any entry gaining its own `runtime_env` re-lists the four `DEFAULTS` guards verbatim: `deep_update` overwrites lists rather than merging them, so declaring one silently drops the OOM / dead-node / object-store checks. (17 entries on master are already missing guards for this reason; pre-existing, not touched here.) `map_benchmark.py` also drops its `use_datasource_v2 = False` pin, which existed because V2 was spilling. > Budgets originally measured against the pre-decoupling design and refined since. Packing moved between stages in #65596 but the packer and its inputs did not, so bins should be unchanged — a release run against this PR is what confirms that. The wide-schema tests are the first place to look. ## Behavior change worth reviewing **Read-task sizing no longer comes from `override_num_blocks` / `read_op_min_num_blocks` for Parquet.** Bins are sized by `RAY_DATA_PARQUET_BIN_PACKING_BYTES`, which is *also* not derived from `DataContext.target_max_block_size`. That decoupling is deliberate — read units are row-group-accurate rather than size-estimated — but it means the two knobs users reach for first no longer affect Parquet read parallelism. Deriving the budget from `target_max_block_size` is worth considering as a follow-up; the per-test overrides above are the evidence that a single global default does not fit every workload. ## Testing ``` $ python -m pytest -q python/ray/data/tests/datasource/test_parquet.py 286 passed, 6 skipped in 521.25s $ python -m pytest -q python/ray/data/tests/datasource/test_read_parquet_v2.py 32 passed $ python -m pytest -q python/ray/data/tests/unit/datasource_v2/ python/ray/data/_internal/datasource_v2/tests/ 181 passed $ python -m pytest -q python/ray/data/tests/test_predicate_pushdown.py \ python/ray/data/tests/test_execution_optimizer_limit_pushdown.py 78 passed ``` The 286-test parquet suite is the one that matters — it runs the full read surface with the footer path as the default rather than behind a flag. The release YAML is additionally checked for parse validity, unresolved `{{...}}` in any pin, duplicate `byod:` keys, and rendered-name stability. ## Stack Final step of an 11-step split of #64985 (43 files / +3234 −719, not reviewable as one unit). - #65167 `[1]` · #65168 `[2]` · #65214 `[3]` · #65210 `[4]` · #65273 `[5]` · #65596 `[6]` · #65806 `[8]` · #65169 `[9]` — all merged - `[7]` (count push-down fix) was absorbed into #65596 - `[10]` (release tuning) is folded into this PR, so a release run exercises the flip and its tuning together - **this PR** `[11/11]` --- Not a duplicate. File-level overlap check: #63158 none; #65142 overlaps `file_indexer.py` / `context.py`; #65406 / #65407 (arrow-rs reader A/B) overlap broadly but are explicitly `[DO NOT MERGE]` benchmark branches carrying the footer work out-of-tree. AI assistance was used; every line reviewed by me and tests run locally. --------- Signed-off-by: Goutam <[email protected]>
…acking as a partitioner (ray-project#65596) ## Why Parquet V2 chunks files **blindly**. `ParquetFileChunker` splits each file by `ceil(file_size / 1 GiB)` *without reading the footer*, and `RoundRobinPartitioner` bin-packs those guesses with a fixed encoding-ratio estimate. Bin sizes are inaccurate because the compression ratio is unknown until the footer is read, there is no row-group skipping, and nothing from predicate / limit / projection push-down reaches listing. This wires steps 1–5 into a working read path — the first PR in the split where the footer path is *reachable*. **Default-off.** Gated on `RAY_DATA_PARQUET_ENABLE_FOOTER_INDEXER`; without it every Parquet V2 read behaves exactly as today. Flipping the default and deleting the blind chunker are separate later steps, which keeps this reviewable and leaves a one-line revert lever. ## What this changes **1. `FooterFileIndexer` — listing that reads footers.** New indexer, returned from `_get_file_indexer()` only when the flag is set. It footer-reads files on a `FooterReader` actor pool (step 5) and emits **one listing row per row-group run**, each carrying that run's exact stats: `num_rows`, `uncompressed_size`, per-row-group `rg_sizes` / `rg_rows`, and `fully_matched`. Actor pool is killed in a `finally`, in-flight footer batches are bounded, and listing stops early once `limit` exact-survivor rows are delivered. **2. Bin packing is a `FilePartitioner`, not an indexer detail.** Listing discovers work; the partitioner groups it. `OnlineBinPacker` (step 4) becomes a real `FilePartitioner` supplied via a new `DataSourceV2.get_file_partitioner()` hook, so it runs in the normal partitioner stage and can split runs at exact row-group boundaries. `FileIndexer.produces_partitioned_manifests` is deleted in favor of `FilePartitioner.requires_global_input`, which is what tells `plan_list_files_op` to keep listing on one task. This is not just tidying — it fixes a parallelism bug. `produces_partitioned_manifests` made the planner skip the partitioner stage entirely, so with `shuffle="files"` the footer path read the **whole dataset in a single task**: `shuffle_files` concatenates every sealed bin into one manifest block, and with no partitioner downstream nothing was left to re-split it. **3. `count()` push-down.** `PushdownCountFiles` tried to force whole-file listing by overwriting the indexer's `_file_chunker`, but `FooterFileIndexer` overrides `list_files` outright and ignores its chunker, so the swap was a silent no-op. It now swaps the indexer itself via `as_whole_file_indexer()`. This is what makes (2) safe: once listing emits a row per row-group run, `read_metadata` returns the whole file's row count for *each* row, so a 4-row-group file counts 4×. The hard `assert isinstance(...)` also becomes a debug log and bail-out, so a third-party indexer falls back to the regular read path instead of crashing the optimizer. **4. `skip_paths` on the footer path.** `FooterFileIndexer` was constructed without it, so `read_parquet(..., skip_paths=...)` silently did nothing when the flag was on — excluded files were read, and a path named only in `skip_paths` could fail the listing instead of being ignored. These land together because (3) guards a bug that (2) introduces, and both touch the same listing contract. ## Flow ```mermaid flowchart TD LF[ListFiles] --> FI[FooterFileIndexer] FI --> LI["list_file_infos<br/>(step 1)"] LI --> BA[batch paths] BA --> AP["FooterReaderActor pool<br/>SPREAD (step 5)"] AP -->|one row per row-group run| SH[shuffle_files] SH --> BP["OnlineBinPacker<br/>(step 4), a FilePartitioner"] BP -->|sealed bins| MB[manifest blocks] MB --> RF[ReadFiles] RF --> PR["ParquetFileReader<br/>reads exactly the named row groups"] LF -.->|"predicate / limit / projected_columns<br/>(step 3)"| FI ``` `OnlineBinPacker.requires_global_input = True` keeps listing on a single task, since the packer holds one pool of open bins across all files. ## Files | File | Change | | --- | --- | | `listing/footer_file_indexer.py` | **new** — `FooterFileIndexer`. All knobs re-read in `__init__` so `monkeypatch.setenv` and release-test overrides apply. | | `listing/file_indexer.py` | drops `produces_partitioned_manifests`; adds `as_whole_file_indexer()` | | `partitioners/online_bin_packer.py` | now a `FilePartitioner` (`add_input`, `requires_global_input`) | | `partitioners/file_partitioner.py` | adds `requires_global_input` | | `datasource_v2.py` / `read_api.py` | new `get_file_partitioner()` hook; default stays `RoundRobinPartitioner` | | `parquet_datasource_v2.py` | flag-gated indexer + packer; wires `skip_paths` | | `planner/plan_list_files_op.py` | partitioner stage always runs; single-task listing keys off `requires_global_input` | | `rules/pushdown_count_files.py` | replaces the indexer instead of reconfiguring it | | `chunkers/file_chunker.py` | `ParquetRowGroupChunkMetadata` gains `fully_matched`, `rg_sizes`, `rg_rows` | | `chunkers/parquet_file_chunking_utils.py` | adds `_fragments_from_row_group_ids`, `_with_io_retry` | | `readers/parquet_file_reader.py` | dispatches on metadata type so both chunkers coexist; sizes batches from footer stats already on the manifest | | `readers/file_reader.py` | `_resolve_batch_size(dataset, manifest)` | ## Testing ``` pytest python/ray/data/tests/unit/datasource_v2/test_file_indexer.py \ python/ray/data/tests/unit/datasource_v2/test_online_bin_packer.py \ python/ray/data/_internal/datasource_v2/tests/test_parquet_datasource_v2.py \ python/ray/data/_internal/datasource_v2/tests/test_footer_chunking.py \ python/ray/data/tests/datasource/test_read_parquet_v2.py # 145 passed ``` The two that carry the most weight: - `test_count_matches_rows`, parametrized over `(4 files, 1000 rows, row_group_size=250)`. This is the guard for (3): without `as_whole_file_indexer()` it fails `assert 4800 == 1200`. - `test_e2e_filter_then_limit_with_nulls`, 20 files at 10% non-null over five limits. If a null were ever counted as an exact survivor, listing would stop short and `Limit` would quietly return fewer rows than asked. (The classification behind that landed in ray-project#65273.) **Known gap:** `skip_paths` has unit coverage in `test_parquet_datasource_v2.py` but no end-to-end test through `read_parquet` on the footer path. ## Stack Step 6 of an 11-step split of ray-project#64985 (43 files, +3234 −719, not reviewable as one unit). - ray-project#65167 `[1/11]` `FileIndexer.list_file_infos` ✅ · ray-project#65168 `[2/11]` limit into `ReadFiles` ✅ - ray-project#65214 `[3/11]` derive `ListFiles` pushdown state ✅ · ray-project#65210 `[4/11]` footer types + bin packer ✅ - ray-project#65273 `[5/11]` `FooterReader` actor pool ✅ - **this PR** — consumes all of the above; first step that makes the path reachable - ray-project#65169 `[9/11]` pin the footer actor pool to 1 in tests (open, independent) This PR **absorbs what was going to be step 7** (`count()` push-down), so the remaining steps renumber down by one. Step 7 can't be split out downstream of this: the packing change is what triggers the over-count, so the fix has to ship at or below it. ## AI assistance AI assistance was used for this change. I have reviewed every changed line and run the tests above locally. Not a duplicate: `gh pr list --repo ray-project/ray --state open --search "FooterFileIndexer"` and `--search "footer indexer parquet"` return only this PR, the stack members listed above, and ray-project#64985 — the mega-PR this stack is splitting up, which closes once the stack lands. --------- Signed-off-by: Goutam <[email protected]> Co-authored-by: Cursor <[email protected]>
…ay-project#65806) ## Why Two independent throughput knobs for the Parquet read task, kept out of the footer-indexer PR because each changes behavior on its own and needs its own justification. **One reader thread per fragment, instead of capping at 4.** The cap existed because the blind `ParquetFileChunker` could put an unbounded number of row groups — and therefore fragments — in a single read task, so an uncapped thread pool was a real risk. Now that ray-project#65596 has landed, read units are bin-packed to a byte budget, so the fragment count per task is bounded by construction and the cap only serializes IO that could overlap. **Size Arrow's IO/CPU pools for the read task.** Arrow's defaults (~num cores, 8 IO threads) throttle the concurrent column/range fetches a Parquet scan issues against S3. That hurts most for row-group-scoped fragments, which is exactly what the footer path now produces. ## Flow No structural change — both are sizing knobs on the existing read path: ``` ReadFiles task ├─ pa.set_io_thread_count / set_cpu_count ← new, at reader construction └─ _read_fragment_batches └─ num_workers = len(fragments) ← was min(4, len(fragments)) ``` The sequential path still applies when `DataContext.execution_options.preserve_order` is set, unchanged. ## What changed | File | Change | | --- | --- | | `readers/file_reader.py` | Drop `_DEFAULT_NUM_THREADS` / `RAY_DATA_READ_FILES_NUM_THREADS`; `num_workers = len(fragments_with_offsets)`. Also fixes the `_read_fragment_batches` docstring, which still documented the removed env var. | | `readers/parquet_file_reader.py` | `pa.set_io_thread_count()` / `pa.set_cpu_count()` at reader construction, from `RAY_DATA_PARQUET_READER_IO_THREAD_COUNT` / `RAY_DATA_PARQUET_READER_CPU_COUNT` (default 128 each; `0` disables). | **Two things worth a careful look:** - This **removes** `RAY_DATA_READ_FILES_NUM_THREADS`. It is undocumented and internal, but anyone setting it loses the knob. - `pa.set_io_thread_count` / `set_cpu_count` mutate **process-global** Arrow state from a constructor. That is deliberate — the read task is the process — but it means a non-Parquet reader sharing the worker sees the same pools. ## Stack Step 8 of an 11-step split of ray-project#64985. - ray-project#65167 `[1/11]` ✅ · ray-project#65168 `[2/11]` ✅ · ray-project#65214 `[3/11]` ✅ · ray-project#65210 `[4/11]` ✅ · ray-project#65273 `[5/11]` ✅ - ray-project#65596 `[6/11]` ✅ — footer indexer behind the flag, which also absorbed step 7's `count()` fix and moved bin packing into a `FilePartitioner` - **this PR** `[8/11]` — unblocked by ray-project#65596: the thread cap can only come off once bins are size-bounded - ray-project#65169 `[9/11]` pin the footer actor pool to 1 in tests (open, independent) Remaining after this: release-test tuning, then flipping the default and deleting the old chunker. --------- Signed-off-by: Goutam <[email protected]>
…ect#65821) ## Why The last step of the split of ray-project#64985: flip Parquet V2 to the footer read path, delete the blind one, and tune the release tests so this can be validated by a real release run. Everything it depends on has landed — footer types and the bin packer (ray-project#65210), the `FooterReader` actor pool (ray-project#65273), the indexer plus `count()` fix and packer-as-partitioner (ray-project#65596), reader IO tuning (ray-project#65806), and test env pinning (ray-project#65169). The path has been reachable behind `RAY_DATA_PARQUET_ENABLE_FOOTER_INDEXER` since ray-project#65596; this makes it the only path. ## Flow ```mermaid flowchart LR RP[read_parquet] --> FF["FooterFileIndexer<br/>+ OnlineBinPacker"] RP -.->|deleted| PC["ParquetFileChunker<br/>size-estimated chunks<br/>+ parquet_chunker_target_chunk_size"] style PC stroke-dasharray: 4 4 ``` ## What changed **The flip** — `RAY_DATA_PARQUET_ENABLE_FOOTER_INDEXER` is gone from both call sites. `_get_file_indexer()` always returns `FooterFileIndexer`; `get_file_partitioner()` always returns `OnlineBinPacker`. **The deletions** — `ParquetFileChunker`, `ParquetFileChunkMetadata`, `_calculate_row_group_range`, `_fragments_from_chunk_metadata`, and the tests covering only that path. **The config it left behind** — `DataContext.parquet_chunker_target_chunk_size` and `DEFAULT_PARQUET_CHUNKER_TARGET_CHUNK_SIZE` were read *only* by `ParquetFileChunker.__init__`, so they would otherwise stay declared and documented while doing nothing. Verified dead by grep across `.py` / `.yaml` / `.rst` / `.md`. **Reader pool defaults** — `RAY_DATA_PARQUET_READER_IO_THREAD_COUNT` 128, `RAY_DATA_PARQUET_READER_CPU_COUNT` 32. ## Release tests tuned Budgets are per-test overrides of `RAY_DATA_PARQUET_BIN_PACKING_BYTES` (uncompressed bytes of row-group data per read task; default 128 MiB). The shape of the tuning: reads over few large groups want **large** bins, because small bins shatter the read into short tasks the executor cannot dispatch fast enough and the cluster idles; shuffle-bound reads over many groups want **small** bins. Rows whose variants all share the same tuning are collapsed and marked. | release test | bin budget | other tuning | | --- | --- | --- | | `aggregate_groups_fixed_size_hash_shuffle_column02 column14` | 32 MiB | — | | `aggregate_groups_fixed_size_hash_shuffle_column08 column13 column14` | 128 MiB | — | | `aggregate_groups_fixed_size_shuffle_v2_column02 column14` | 64 MiB | — | | `aggregate_groups_fixed_size_shuffle_v2_column08 column13 column14` | 512 MiB | — | | `aggregate_groups_fixed_size_sort_shuffle_pull_based_column02 column14` | 32 MiB | — | | `aggregate_groups_fixed_size_sort_shuffle_pull_based_column08 column13 column14` | 256 MiB | — | | `count_parquet_fixed_size` | 64 MiB | — | | `cross_az_map_batches_autoscaling_iptable_failure_injection` | 1 GiB | — | | `distributed_training` | — | footer actors `20` | | `flat_map` | 64 MiB | — | | `iceberg_benchmark_overwrite` | 64 MiB | — | | `iter_batches_pyarrow` | 64 MiB | — | | `iter_torch_batches` | 64 MiB | — | | `joins_{{dataset}}_{{join_type}} *(all 4 variants)*` | 1.25 GiB | — | | `map` | 64 MiB | — | | `map_batches_fixed_size_{{compute}}_{{format}}_{{repeat_map_batches}} *(all 7 variants)*` | 1 GiB | scale-up threshold `0.6` | | `map_groups_fixed_size_{{shuffle_strategy}}_{{columns}} *(all 6 variants)*` | 1.25 GiB | — | | `mix` | — | footer actors `4` | | `random_shuffle_fixed_size` | 64 MiB | — | | `read_large_parquet_fixed_size` | 1 GiB | — | | `read_parquet_fixed_size` | 64 MiB | — | | `read_tfrecords` | 64 MiB | — | | `streaming_split` | 64 MiB | footer batch `50`, result batch `50` | | `to_tf` | 64 MiB | — | | `tpch_q1_fixed_size_{{shuffle_strategy}} *(all 2 variants)*` | 192 MiB | — | | `training_ingest_benchmark` | 64 MiB | — | | `wide_schema_pipeline_nested_structs` | 2 MiB | footer batch `1`, footer actors `21`, io threads `5000` | | `wide_schema_pipeline_objects` | 4.2 MiB | footer batch `1`, footer actors `9`, io threads `5000` | | `wide_schema_pipeline_primitives` | 256 KiB | footer batch `1`, footer actors `27`, io threads `5000` | | `wide_schema_pipeline_tensors` | 39 MiB | footer batch `1`, footer actors `22`, io threads `5000` | | `write_parquet` | 1.25 GiB | — | **Three matrices are split**, because a matrix cannot vary `byod.runtime_env` per value and their variants want different budgets: `wide_schema_pipeline_{{data_type}}` into four entries, and one variant each out of `iceberg_benchmark_{{mode}}` and `iter_batches_{{format}}`. `aggregate_groups` keeps its matrix and carries the budget as a matrix dimension with explicit adjustments. **Rendered test names are unchanged — 121 before and after** — so release baselines still line up. **Not carried over** from the original branch: 7 previously-pinned entries no longer exist — the autoscaling variants removed in ray-project#65506, plus `tpch_q20` and `tpch_q22`. Any entry gaining its own `runtime_env` re-lists the four `DEFAULTS` guards verbatim: `deep_update` overwrites lists rather than merging them, so declaring one silently drops the OOM / dead-node / object-store checks. (17 entries on master are already missing guards for this reason; pre-existing, not touched here.) `map_benchmark.py` also drops its `use_datasource_v2 = False` pin, which existed because V2 was spilling. > Budgets originally measured against the pre-decoupling design and refined since. Packing moved between stages in ray-project#65596 but the packer and its inputs did not, so bins should be unchanged — a release run against this PR is what confirms that. The wide-schema tests are the first place to look. ## Behavior change worth reviewing **Read-task sizing no longer comes from `override_num_blocks` / `read_op_min_num_blocks` for Parquet.** Bins are sized by `RAY_DATA_PARQUET_BIN_PACKING_BYTES`, which is *also* not derived from `DataContext.target_max_block_size`. That decoupling is deliberate — read units are row-group-accurate rather than size-estimated — but it means the two knobs users reach for first no longer affect Parquet read parallelism. Deriving the budget from `target_max_block_size` is worth considering as a follow-up; the per-test overrides above are the evidence that a single global default does not fit every workload. ## Testing ``` $ python -m pytest -q python/ray/data/tests/datasource/test_parquet.py 286 passed, 6 skipped in 521.25s $ python -m pytest -q python/ray/data/tests/datasource/test_read_parquet_v2.py 32 passed $ python -m pytest -q python/ray/data/tests/unit/datasource_v2/ python/ray/data/_internal/datasource_v2/tests/ 181 passed $ python -m pytest -q python/ray/data/tests/test_predicate_pushdown.py \ python/ray/data/tests/test_execution_optimizer_limit_pushdown.py 78 passed ``` The 286-test parquet suite is the one that matters — it runs the full read surface with the footer path as the default rather than behind a flag. The release YAML is additionally checked for parse validity, unresolved `{{...}}` in any pin, duplicate `byod:` keys, and rendered-name stability. ## Stack Final step of an 11-step split of ray-project#64985 (43 files / +3234 −719, not reviewable as one unit). - ray-project#65167 `[1]` · ray-project#65168 `[2]` · ray-project#65214 `[3]` · ray-project#65210 `[4]` · ray-project#65273 `[5]` · ray-project#65596 `[6]` · ray-project#65806 `[8]` · ray-project#65169 `[9]` — all merged - `[7]` (count push-down fix) was absorbed into ray-project#65596 - `[10]` (release tuning) is folded into this PR, so a release run exercises the flip and its tuning together - **this PR** `[11/11]` --- Not a duplicate. File-level overlap check: ray-project#63158 none; ray-project#65142 overlaps `file_indexer.py` / `context.py`; ray-project#65406 / ray-project#65407 (arrow-rs reader A/B) overlap broadly but are explicitly `[DO NOT MERGE]` benchmark branches carrying the footer work out-of-tree. AI assistance was used; every line reviewed by me and tests run locally. --------- Signed-off-by: Goutam <[email protected]>

Why
Parquet V2 chunks files blindly.
ParquetFileChunkersplits each file byceil(file_size / 1 GiB)without reading the footer, andRoundRobinPartitionerbin-packs those guesses with a fixed encoding-ratio estimate. Bin sizes are inaccurate because the compression ratio is unknown until the footer is read, there is no row-group skipping, and nothing from predicate / limit / projection push-down reaches listing.This wires steps 1–5 into a working read path — the first PR in the split where the footer path is reachable.
Default-off. Gated on
RAY_DATA_PARQUET_ENABLE_FOOTER_INDEXER; without it every Parquet V2 read behaves exactly as today. Flipping the default and deleting the blind chunker are separate later steps, which keeps this reviewable and leaves a one-line revert lever.What this changes
1.
FooterFileIndexer— listing that reads footers. New indexer, returned from_get_file_indexer()only when the flag is set. It footer-reads files on aFooterReaderactor pool (step 5) and emits one listing row per row-group run, each carrying that run's exact stats:num_rows,uncompressed_size, per-row-grouprg_sizes/rg_rows, andfully_matched. Actor pool is killed in afinally, in-flight footer batches are bounded, and listing stops early oncelimitexact-survivor rows are delivered.2. Bin packing is a
FilePartitioner, not an indexer detail. Listing discovers work; the partitioner groups it.OnlineBinPacker(step 4) becomes a realFilePartitionersupplied via a newDataSourceV2.get_file_partitioner()hook, so it runs in the normal partitioner stage and can split runs at exact row-group boundaries.FileIndexer.produces_partitioned_manifestsis deleted in favor ofFilePartitioner.requires_global_input, which is what tellsplan_list_files_opto keep listing on one task.This is not just tidying — it fixes a parallelism bug.
produces_partitioned_manifestsmade the planner skip the partitioner stage entirely, so withshuffle="files"the footer path read the whole dataset in a single task:shuffle_filesconcatenates every sealed bin into one manifest block, and with no partitioner downstream nothing was left to re-split it.3.
count()push-down.PushdownCountFilestried to force whole-file listing by overwriting the indexer's_file_chunker, butFooterFileIndexeroverrideslist_filesoutright and ignores its chunker, so the swap was a silent no-op. It now swaps the indexer itself viaas_whole_file_indexer(). This is what makes (2) safe: once listing emits a row per row-group run,read_metadatareturns the whole file's row count for each row, so a 4-row-group file counts 4×. The hardassert isinstance(...)also becomes a debug log and bail-out, so a third-party indexer falls back to the regular read path instead of crashing the optimizer.4.
skip_pathson the footer path.FooterFileIndexerwas constructed without it, soread_parquet(..., skip_paths=...)silently did nothing when the flag was on — excluded files were read, and a path named only inskip_pathscould fail the listing instead of being ignored.These land together because (3) guards a bug that (2) introduces, and both touch the same listing contract.
Flow
OnlineBinPacker.requires_global_input = Truekeeps listing on a single task, since the packer holds one pool of open bins across all files.Files
listing/footer_file_indexer.pyFooterFileIndexer. All knobs re-read in__init__somonkeypatch.setenvand release-test overrides apply.listing/file_indexer.pyproduces_partitioned_manifests; addsas_whole_file_indexer()partitioners/online_bin_packer.pyFilePartitioner(add_input,requires_global_input)partitioners/file_partitioner.pyrequires_global_inputdatasource_v2.py/read_api.pyget_file_partitioner()hook; default staysRoundRobinPartitionerparquet_datasource_v2.pyskip_pathsplanner/plan_list_files_op.pyrequires_global_inputrules/pushdown_count_files.pychunkers/file_chunker.pyParquetRowGroupChunkMetadatagainsfully_matched,rg_sizes,rg_rowschunkers/parquet_file_chunking_utils.py_fragments_from_row_group_ids,_with_io_retryreaders/parquet_file_reader.pyreaders/file_reader.py_resolve_batch_size(dataset, manifest)Testing
The two that carry the most weight:
test_count_matches_rows, parametrized over(4 files, 1000 rows, row_group_size=250). This is the guard for (3): withoutas_whole_file_indexer()it failsassert 4800 == 1200.test_e2e_filter_then_limit_with_nulls, 20 files at 10% non-null over five limits. If a null were ever counted as an exact survivor, listing would stop short andLimitwould quietly return fewer rows than asked. (The classification behind that landed in [Data] [5/11] Add the Parquet FooterReader actor pool #65273.)Known gap:
skip_pathshas unit coverage intest_parquet_datasource_v2.pybut no end-to-end test throughread_parqueton the footer path.Stack
Step 6 of an 11-step split of #64985 (43 files, +3234 −719, not reviewable as one unit).
[1/11]FileIndexer.list_file_infos✅ · [Data] [2/11] Push limit into ReadFiles when Limit sits directly on it #65168[2/11]limit intoReadFiles✅[3/11]deriveListFilespushdown state ✅ · [Data] [4/11] Add Parquet footer types and the online bin packer #65210[4/11]footer types + bin packer ✅[5/11]FooterReaderactor pool ✅[9/11]pin the footer actor pool to 1 in tests (open, independent)This PR absorbs what was going to be step 7 (
count()push-down), so the remaining steps renumber down by one. Step 7 can't be split out downstream of this: the packing change is what triggers the over-count, so the fix has to ship at or below it.AI assistance
AI assistance was used for this change. I have reviewed every changed line and run the tests above locally.
Not a duplicate:
gh pr list --repo ray-project/ray --state open --search "FooterFileIndexer"and--search "footer indexer parquet"return only this PR, the stack members listed above, and #64985 — the mega-PR this stack is splitting up, which closes once the stack lands.