Skip to content

[Data] [5/11] Add the Parquet FooterReader actor pool - #65273

Merged
goutamvenkat-anyscale merged 16 commits into
ray-project:masterfrom
goutamvenkat-anyscale:goutam/data-parquet-footer-reader
Aug 19, 2026
Merged

goutamvenkat-anyscale merged 16 commits into
ray-project:masterfrom
goutamvenkat-anyscale:goutam/data-parquet-footer-reader

Conversation

@goutamvenkat-anyscale

@goutamvenkat-anyscale goutamvenkat-anyscale commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Why

Footer IO for the footer-based Parquet chunking path (the rest of the split of #64985).

Reading N Parquet footers serially on the driver doesn't scale — it's the step that decides which row groups a read even touches. FooterReader runs as a pool of Ray actors, each reading footers on its own thread pool and streaming results back in batches, so footer IO spreads across the cluster instead of bottlenecking on one process.

Nothing constructs it yet — it's unused until the footer indexer lands in step 6.

Flow

Per file, it produces the row-group descriptors the bin packer (merged in #65210) consumes:

flowchart LR
  B["(path, size) batch"] --> A["FooterReaderActor<br/>SPREAD across the cluster"]
  A --> R[read footer]
  R --> F["split_by_row_group(filter)<br/>prune by statistics"]
  F --> Q["split_by_row_group(~filter)<br/>classify fully_matched"]
  Q --> C["coalesce_row_groups<br/>(from #65210)"]
  C --> O["stream List[FileChunks]<br/>batched by result_batch_size"]
Loading

Three things it decides, each of which the packer and the limit push-down depend on:

  • Predicate pruning. fragment.split_by_row_group(filter) drops row groups whose Parquet statistics contradict the pushed filter, so they never reach the packer at all.
  • fully_matched classification. A surviving group is fully matched iff ~filter prunes it entirely. Only fully-matched groups have an exact survivor count, and only exact counts may drive limit push-down. Any failure defaults to not-fully-matched, which is always the safe direction. This is the correctness-critical bit: nulls are the interesting case, since Parquet min/max stats are computed over non-null values only, so a group whose non-null values all satisfy the filter looks fully matched by bounds alone while its null rows don't survive.
  • Projection-scoped sizing. Byte sizes are accounted over only the projected leaf columns, so bins get sized for what the reader will actually fetch. Nested columns expand to all their leaves.

What changed

Two new files, 368 insertions, 0 deletions:

File Change
listing/footer_reader.py new — FooterReader plus FooterReaderActor = ray.remote(FooterReader). Kept as a plain class with the actor built via the functional form, so callers can type handles as ActorProxy[FooterReader]. read_footers is a streaming @ray.method generator that yields List[FileChunks], batched by result_batch_size — the driver pays one object-store fetch per yielded list, so batching cuts driver-side deserialization roughly proportionally.
tests/test_footer_reader.py new — 14 tests

Testing

The tests drive the plain class directly against local Parquet fixtures — no actor, no cluster. Coverage is aimed at the decisions above rather than the plumbing: predicate pruning by statistics, the partial-match case (id >= 30 splitting a row group, which must not count as exact), a predicate matching nothing, projection shrinking accounted size while leaving row counts alone, coalescing preserving total rows, nested columns expanding to all leaves, and result batching at several result_batch_size values.

$ python -m pytest -q python/ray/data/_internal/datasource_v2/tests/test_footer_reader.py
14 passed in 4.30s

$ python -m pytest -q python/ray/data/_internal/datasource_v2/tests/ python/ray/data/tests/unit/datasource_v2/
145 passed in 0.90s

Stack

Step 5 of an 11-step split of #64985, which was 43 files / +3234 −719 and not reviewable as one unit.

Step 6 wires this and the packer together behind an opt-in flag, and needs both this and #65214.


Not a duplicate of any open PR (checked gh pr list --state open plus a file-level overlap check against #65142 / #63158 / #64404 — no overlap; only #64985, which this replaces).
AI assistance was used; every line reviewed by me and tests run locally.

Footer IO for the upcoming footer-based chunking path. Reading N footers
serially on the driver does not scale, so `FooterReader` runs as a pool of
Ray actors, each reading footers on its own thread pool and streaming
results back in batches.

Per file it produces the row-group descriptors the bin packer needs:

- Predicate push-down via `split_by_row_group(filter)`, so row groups whose
  statistics contradict the filter never reach the packer.
- A `fully_matched` flag per surviving group, derived by checking whether
  `~filter` prunes the group entirely (as DataFusion does). Only fully
  matched groups have an exact survivor count, which is what makes limit
  push-down sound. Any failure defaults to not-fully-matched, which is
  always safe.
- Projection-scoped byte sizes, so bins are sized for the columns the
  reader will actually fetch.

Unused so far. Tests drive the plain class directly against local
fixtures -- no cluster -- and cover the partial-match case that limit
push-down correctness depends on.

Signed-off-by: Goutam <[email protected]>
@goutamvenkat-anyscale goutamvenkat-anyscale added data Ray Data-related issues go add ONLY when ready to merge, run all tests labels Aug 7, 2026
@goutamvenkat-anyscale
goutamvenkat-anyscale marked this pull request as ready for review August 7, 2026 01:41
@goutamvenkat-anyscale
goutamvenkat-anyscale requested a review from a team as a code owner August 7, 2026 01:41

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces the FooterReader class to concurrently read Parquet footers and chunk files into row-group runs, along with corresponding unit tests. The review feedback identifies a critical correctness bug where row groups containing null values in filtered columns can be incorrectly marked as fully matched, which would lead to incorrect downstream row counts. Additionally, the feedback suggests avoiding over-subscribing Arrow's CPU thread pool by removing the CPU count configuration that matches the high I/O concurrency limit, and recommends adding a test case to verify the handling of null values during filtering.

Comment on lines +61 to +64
by_idx = {rg.rg_idx: rg.fully_matched for rg in chunks.row_groups}
assert by_idx[1] is False, "partially matching group must not count as exact"
assert by_idx[2] is True
assert by_idx[3] is True

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Please add a test case to verify the behavior of fully_matched when there are Null values in the filtered column. This will help prevent regressions and ensure correctness.

Example test case:

    def test_fully_matched_with_nulls(self, tmp_path):
        # Create a table with nulls in the filtered column
        table = pa.table({"id": [35, 40, 45, None]})
        path, size = _write(tmp_path / "nulls.parquet", table, row_group_size=4)
        
        # id >= 30 should NOT mark the row group as fully matched because of the null
        chunks = _reader(filter_expr=col("id") >= 30)._read_and_chunk(path, size)
        assert len(chunks.row_groups) == 1
        assert chunks.row_groups[0].fully_matched is False

Parquet min/max statistics are computed over non-null values only, so bounds
alone can never rule out nulls. Under three-valued logic a row whose predicate
column is null satisfies neither `filter` nor `~filter`, so the negation test
on its own is not sufficient: a group of [35, 40, 45, NULL] under `id >= 30`
can have `~filter` prune it while one row did not actually survive. `num_rows`
then over-counts, and limit push-down stops early and silently under-delivers.

PyArrow declines that prune today -- it does not use `null_count` to sharpen
the inverted predicate -- so the negation test is currently safe by accident.
That is not a property of our code, and the failure mode if it ever changes is
a wrong answer with no error.

Check `null_count` on the predicate's columns directly instead. That holds
regardless of how sharp the engine's statistics pruning gets, and costs one
pass over already-loaded footer metadata. Missing or absent null counts are
treated as may-contain-nulls, the safe direction.

Adds a regression test that stands in for an engine which does prune the
inverted predicate; against the previous logic it claims 4 exact survivors out
of 3 real ones.

Signed-off-by: Goutam <[email protected]>
The no-projection path took uncompressed_size from
`row_group.total_byte_size`, which can report the *compressed* size for some
files (apache/arrow#48138). That undersizes bins, and undersized bins overfill
read tasks -- the exact failure this path exists to prevent.

Both existing helpers already avoid the accessor for this reason:
`_row_group_uncompressed_size` in parquet_datasource.py and the metadata
estimator in parquet_file_reader.py. Reuse the former, which already handles
both the all-columns and projected-leaves cases, so the three call sites
cannot drift.

The dropped comment claimed total_byte_size was worth it as a single cheap
accessor. It is cheap -- measured 7591x cheaper than the walk on a
1000-column schema -- but the fast path only applied when there was neither a
projection nor a filter, since both of those already walk columns. Measured
end-to-end cost of `_read_and_chunk`: 0.93 -> 1.95 ms for a typical
20-column/100-row-group file, 12.5 -> 20.9 ms for an extreme
1000-column/20-row-group one. Footer reads are network-bound at tens of ms
each, so this is well inside the noise, and correctness is not worth trading
for it.

Signed-off-by: Goutam <[email protected]>
…ched

Two defects in the null guard, both of which silently skip it.

Matching compared only the first dot-separated segment of `path_in_schema`.
That is right for a nested leaf (`outer.a` under `outer`) and wrong for a flat
column whose *name* contains a dot -- `sepal.length`, from the iris dataset, is
one. `get_column_references` yields `sepal.length`, the leaf path is
`sepal.length`, and the first segment `sepal` matches nothing.

When nothing matched, the loop fell through to `return False` -- reported as
"no nulls in the predicate's columns" when the truth is "we never found them".
A predicate column absent from the footer is unverified, not null-free.

Match the whole leaf path first, then the descendant prefix, which is the rule
`_estimate_batch_size_from_metadata` already uses; and return True unless every
predicate column was located. Applied to `_projected_leaf_indices` too, where
the same mismatch silently drops a dotted column from the projected size and
undersizes its bin.

Against the previous logic a `sepal.length` group of [35, 40, 45, NULL] under
`>= 30` claims 4 exact survivors out of 3.

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

@rayhhome rayhhome left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry for the late comments!

Comment on lines +108 to +112
return [
j
for j in range(row_group.num_columns)
if _leaf_matches(row_group.column(j).path_in_schema, self.projected_cols)
]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In hive-style partitioning, a column's value can be encoded in the directory name instead of inside the files (e.g. s3://bucket/events/year=2024/part-0.parquet). I think this might lead to a peculiar edge case where self.projected_cols only contain synthetic columns (year in the above example) here. The function would return [] in that case, leading to _row_group_uncompressed_size(rg, []) returning 0. This would end up putting all row groups in bin (since used_bytes would always stay 0), and consequently in one task, breaking parallelism.

Schema drift might also lead to this issue but is much less likely since we sample the schema across 16 files.

I believe the following would patch the issue:

Suggested change
return [
j
for j in range(row_group.num_columns)
if _leaf_matches(row_group.column(j).path_in_schema, self.projected_cols)
]
indices = [
j
for j in range(row_group.num_columns)
if _leaf_matches(row_group.column(j).path_in_schema, self.projected_cols)
]
return indices or None

Comment on lines +156 to +157
if column.path_in_schema == name
or column.path_in_schema.startswith(f"{name}.")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: I feel we can extract the predicate used here as a helper function since the same predicate is used in _leaf_matches and line 99 to 102 in parquet_file_reader.py:

def _prefix_match(path: str, names: Set[str]) -> Set[str]:
    return {n for n in names if path == n or path.startswith(f"{n}.")}

Then _leaf_matches is just:

def _leaf_matches(leaf_path: str, names: Set[str]) -> bool:
    return bool(_prefix_match(leaf_path, names))

Also the _leaf_matches and matched.updated actually repeated the same linear computation for the predicate.

Signed-off-by: Goutam <[email protected]>
if _leaf_matches(row_group.column(j).path_in_schema, self.projected_cols)
]

return indices or None

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Empty projection sized as all columns

Medium Severity

_projected_leaf_indices returns indices or None, so an empty match becomes None, which _row_group_uncompressed_size treats as every column. When a projection matches no leaves — empty projected_cols, or a file missing those columns — byte sizes jump to the full row group instead of zero, breaking projection-scoped bin sizing.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 87f755f. Configure here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This comment is not applicable since if the column doesn't match any of the prefixes, that error should be caught when doing the projection pushdown not when doing the listfiles operation.

@rayhhome rayhhome left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Some more comments!

@ayushk7102

Copy link
Copy Markdown
Contributor

What changed

Two new files, 368 insertions, 0 deletions:

Nit: let's update the PR description

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

@ayushk7102 ayushk7102 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor nits, otherwise LGTM

def __init__(
self,
filesystem: pafs.FileSystem,
io_concurrency: int = 128,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should document why we arrive on 128 for a default io_concurrency value here. Maybe we should case this default on whether the filesystem is S3 or local?

i.e. something like:

if (isinstance(filesystem, LocalFileSystem)):
    io_concurrency = 8 

elif (isinstance(filesystem, S3FileSystem)):
    io_concurrency = 128  # higher concurrency because network round-trip

High concurrency might make sense for remote reads from S3 (which I recognise is probably the most common case), but could this be a bottleneck when reading from HDD? The size of the I/O thread pool currently defaults to 8 threads which Arrow explicitly mentions in the docs as being a reasonable default for HDD

https://arrow.apache.org/docs/cpp/threading.html

@rayhhome rayhhome left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM; there's one potential edge case regression pointed out by cursor but i don't think it's blocking. Also check out Ayush's reviews!

Signed-off-by: Goutam <[email protected]>
@goutamvenkat-anyscale
goutamvenkat-anyscale enabled auto-merge (squash) August 15, 2026 03:58
@github-actions
github-actions Bot disabled auto-merge August 15, 2026 04:54
@goutamvenkat-anyscale
goutamvenkat-anyscale enabled auto-merge (squash) August 17, 2026 06:48
@github-actions
github-actions Bot disabled auto-merge August 17, 2026 20:06
@goutamvenkat-anyscale
goutamvenkat-anyscale enabled auto-merge (squash) August 17, 2026 20:06
@github-actions
github-actions Bot disabled auto-merge August 18, 2026 18:12
@goutamvenkat-anyscale
goutamvenkat-anyscale enabled auto-merge (squash) August 18, 2026 18:13
@github-actions
github-actions Bot disabled auto-merge August 19, 2026 09:12

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 95e8237. Configure here.

Signed-off-by: Goutam <[email protected]>
@goutamvenkat-anyscale
goutamvenkat-anyscale enabled auto-merge (squash) August 19, 2026 11:22
@goutamvenkat-anyscale
goutamvenkat-anyscale merged commit 49cc4c5 into ray-project:master Aug 19, 2026
7 checks passed
@goutamvenkat-anyscale
goutamvenkat-anyscale deleted the goutam/data-parquet-footer-reader branch August 19, 2026 12:14
goutamvenkat-anyscale added a commit that referenced this pull request Aug 31, 2026
…acking as a partitioner (#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 #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 #64985 (43 files, +3234 −719, not
reviewable as one unit).

- #65167 `[1/11]` `FileIndexer.list_file_infos` ✅ · #65168 `[2/11]`
limit into `ReadFiles` ✅
- #65214 `[3/11]` derive `ListFiles` pushdown state ✅ · #65210 `[4/11]`
footer types + bin packer ✅
- #65273 `[5/11]` `FooterReader` actor pool ✅
- **this PR** — consumes all of the above; first step that makes the
path reachable
- #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 #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]>
goutamvenkat-anyscale added a commit that referenced this pull request Aug 31, 2026
…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]>
goutamvenkat-anyscale added a commit that referenced this pull request Sep 2, 2026
## 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]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
)

## Why

Footer IO for the footer-based Parquet chunking path (the rest of the
split of ray-project#64985).

Reading N Parquet footers serially on the driver doesn't scale — it's
the step that decides which row groups a read even touches.
`FooterReader` runs as a pool of Ray actors, each reading footers on its
own thread pool and streaming results back in batches, so footer IO
spreads across the cluster instead of bottlenecking on one process.

**Nothing constructs it yet** — it's unused until the footer indexer
lands in step 6.

## Flow

Per file, it produces the row-group descriptors the bin packer (merged
in ray-project#65210) consumes:

```mermaid
flowchart LR
  B["(path, size) batch"] --> A["FooterReaderActor<br/>SPREAD across the cluster"]
  A --> R[read footer]
  R --> F["split_by_row_group(filter)<br/>prune by statistics"]
  F --> Q["split_by_row_group(~filter)<br/>classify fully_matched"]
  Q --> C["coalesce_row_groups<br/>(from ray-project#65210)"]
  C --> O["stream List[FileChunks]<br/>batched by result_batch_size"]
```

Three things it decides, each of which the packer and the limit
push-down depend on:

- **Predicate pruning.** `fragment.split_by_row_group(filter)` drops row
groups whose Parquet statistics contradict the pushed filter, so they
never reach the packer at all.
- **`fully_matched` classification.** A surviving group is *fully*
matched iff `~filter` prunes it entirely. Only fully-matched groups have
an exact survivor count, and only exact counts may drive limit
push-down. Any failure defaults to not-fully-matched, which is always
the safe direction. **This is the correctness-critical bit**: nulls are
the interesting case, since Parquet min/max stats are computed over
non-null values only, so a group whose non-null values all satisfy the
filter looks fully matched by bounds alone while its null rows don't
survive.
- **Projection-scoped sizing.** Byte sizes are accounted over only the
projected leaf columns, so bins get sized for what the reader will
actually fetch. Nested columns expand to all their leaves.

## What changed

Two new files, 368 insertions, 0 deletions:

| File | Change |
| --- | --- |
| `listing/footer_reader.py` | **new** — `FooterReader` plus
`FooterReaderActor = ray.remote(FooterReader)`. Kept as a plain class
with the actor built via the functional form, so callers can type
handles as `ActorProxy[FooterReader]`. `read_footers` is a streaming
`@ray.method` generator that yields `List[FileChunks]`, batched by
`result_batch_size` — the driver pays one object-store fetch per yielded
list, so batching cuts driver-side deserialization roughly
proportionally. |
| `tests/test_footer_reader.py` | **new** — 14 tests |

## Testing

The tests drive the plain class directly against local Parquet fixtures
— no actor, no cluster. Coverage is aimed at the decisions above rather
than the plumbing: predicate pruning by statistics, the partial-match
case (`id >= 30` splitting a row group, which must **not** count as
exact), a predicate matching nothing, projection shrinking accounted
size while leaving row counts alone, coalescing preserving total rows,
nested columns expanding to all leaves, and result batching at several
`result_batch_size` values.

```
$ python -m pytest -q python/ray/data/_internal/datasource_v2/tests/test_footer_reader.py
14 passed in 4.30s

$ python -m pytest -q python/ray/data/_internal/datasource_v2/tests/ python/ray/data/tests/unit/datasource_v2/
145 passed in 0.90s
```

## Stack

Step 5 of an 11-step split of ray-project#64985, which was 43 files / +3234 −719
and not reviewable as one unit.

- ray-project#65167 `[1/11]` Extract `FileIndexer.list_file_infos` ✅ merged
- ray-project#65168 `[2/11]` Push limit into `ReadFiles` when `Limit` sits directly
on it ✅ merged
- ray-project#65214 `[3/11]` Derive `ListFiles` pushdown state from the scanner ✅
merged
- ray-project#65210 `[4/11]` Parquet footer types + online bin packer ✅ merged
- **this PR** `[5/11]` — depends on ray-project#65210 for `parquet_footer_types`
and `parquet_row_group_coalescing`
- ray-project#65169 `[9/11]` Pin the Parquet footer actor pool to 1 in tests (open,
independent)

Step 6 wires this and the packer together behind an opt-in flag, and
needs both this and ray-project#65214.

---
Not a duplicate of any open PR (checked `gh pr list --state open` plus a
file-level overlap check against ray-project#65142 / ray-project#63158 / ray-project#64404 — no overlap;
only ray-project#64985, which this replaces).
AI assistance was used; every line reviewed by me and tests run locally.

---------

Signed-off-by: Goutam <[email protected]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…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]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…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]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

data Ray Data-related issues go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants