Skip to content

[Data] DSv2 Reorg [3/6]: Replace the include_paths and include_row_hash flags with SynthesizedColumn objects - #66390

Merged
goutamvenkat-anyscale merged 6 commits into
ray-project:masterfrom
AarryaSaraf:dsv2-synthesized-columns
Sep 23, 2026
Merged

goutamvenkat-anyscale merged 6 commits into
ray-project:masterfrom
AarryaSaraf:dsv2-synthesized-columns

Conversation

@AarryaSaraf

@AarryaSaraf AarryaSaraf commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Description

include_paths=True adds a path column to every row and
include_row_hash=True adds row_hash. Each is a boolean threaded through
ParquetDatasourceV2 → ParquetScanner → ParquetFileReader → FileReader,
and each boolean drives the same steps written out by hand: advertise the
column in the schema, keep pyarrow from looking for it in the file, skip it
when a projection dropped it, build it per batch, and (for row_hash) scan one
row group at a time so the value can depend on the row's position. The
checkpointing work (#65885, reverted; #65887) needs a third such column and
added a third boolean plus a 130-line copy of the read loop.

This PR replaces the booleans with SynthesizedColumn objects. The reader does
the steps once for whatever columns it is given; a new column is a small class
and touches no reader code.

What changes

  1. readers/synthesized_columns.py (new). SynthesizedColumn with
    name, type, requires_read_unit_boundaries and compute(position, num_rows); ReadUnitPosition (the read unit a table of rows came from
    plus its row offsets); PathColumn and RowHashColumn.
    _compute_row_hashes and the two column-name constants move here from
    file_reader.py, which re-exports them for the legacy datasource.
  2. read_units.py (new). ReadUnit: the piece of a file a reader scans on
    its own, a row group or a whole file, with a stable id (<path>#rg<i>),
    its index, the file's group count and its row count. This is what a
    checkpoint ID column needs to name a row.
  3. parquet_datasource_v2.py. The two flags become a tuple of column
    objects; infer_schema appends each column's name and type in one loop.
    The unused include_paths property is gone.
  4. scanners/parquet_scanner.py. One synthesized_columns field replaces
    the two booleans; read_schema loops over it with the same skip rules.
  5. readers/file_reader.py. Constructor takes the tuple. The pyarrow
    schema strips the configured column names. _get_fragments_to_read returns
    (fragment, ReadUnit, file_row_offset) and the read loop yields (table, ReadUnitPosition). The row_hash block becomes a loop over the columns; the
    path line leaves the partition block because PathColumn goes through the
    same loop.
  6. readers/parquet_file_reader.py and
    chunkers/parquet_file_chunking_utils.py. Per-row-group fan-out is
    keyed on "any column requires boundaries" instead of include_row_hash, and
    each sub-fragment comes back with its ReadUnit. Same footer read, same
    condition.
  7. Tests. tests/unit/datasource_v2/test_synthesized_columns.py (new):
    fan-out is one unit per file unless a column needs boundaries, a whole-file
    manifest row stays one unit, row_hash is identical whole-file vs
    per-row-group, a same-named file column is replaced, read_schema respects
    projection. Three asserts in test_parquet_datasource_v2.py updated.

Before / after: adding a column

Before, #65885 added generated_id_column as a third boolean: +160 lines
across four datasource_v2 files, 129 of them a ParquetFileReader override
duplicating _read_fragments_sequential. After, the same column is one class
next to RowHashColumn and no reader change:

class CheckpointIdColumn(SynthesizedColumn):
    name = ...; type = GENERATED_ID_COLUMN_TYPE
    requires_read_unit_boundaries = True

    def compute(self, position, num_rows):
        u = position.unit
        return get_generated_id_column(u.source, u.index, u.count, u.num_rows,
                                       position.unit_row_offset, num_rows)

Behavior

Row order, appended-column order (partitions, path, row_hash), the row-hash
arithmetic, retry scoping and the fan-out condition are unchanged. One
intended fix: for a file that already has a non-string column named path,
read with include_paths=True, ds.schema() now says path: string, which is
what the blocks always carried. Related to that, the schema handed to pyarrow
strips path only when PathColumn is configured, where it used to strip it
unconditionally.

Additional information

Not a duplicate: no open PR introduces column objects or read units. #65887
(checkpoint skipping) edits the same reader files with its own booleans; this
PR is the seam that work can move onto. #65989 (mine) is about predicates
naming a synthesized column and is independent.

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

pytest -q tests/unit/datasource_v2   # 133 passed

ruff, black and pydoclint at the pre-commit pins are clean; pyrefly
via ci/lint/pyrefly-check.sh reports 59 errors against 61 on the base, none
new.

Written with Claude Code; I reviewed every changed line and ran the tests above.

🤖 Generated with Claude Code

@AarryaSaraf AarryaSaraf added the data Ray Data-related issues label Sep 23, 2026
…sh flags with SynthesizedColumn objects

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Aarrya <[email protected]>
@AarryaSaraf
AarryaSaraf force-pushed the dsv2-synthesized-columns branch from 5057cbe to 992f1fe Compare September 23, 2026 00:17
path = fragment.path
if not per_row_group_offsets:
return [(_subset(ids), 0)]
return [(_subset(ids), ReadUnit(id=path, source=path, count=1), 0)]

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.

Let's not use polymorphic classes.

Comment on lines +1 to +6
"""Read units: the pieces of an input split a reader scans on their own.

Today a read unit is a Parquet row group, or a whole file when the manifest
carries no row-group breakdown. The reader reports each batch's unit through
:class:`~ray.data._internal.datasource_v2.readers.synthesized_columns.BatchOrigin`,
so a synthesized column can position every row within its file.

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.

Modify the description so that it says something along the lines of:
It's a unit of work for subfiles

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.

Parquet row groups is just one such example of the read unit

id=f"{path}#rg{rg_id}",
source=path,
index=rg_id,
count=metadata.num_row_groups,

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.

  1. Let's understand what this property is being used for.
  2. Since the value doesn't change across files, let's only propagate once per file.


@DeveloperAPI
@dataclass(frozen=True)
class BatchOrigin:

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.

ReadUnitMetadata

…escribe read units as sub-file units of work

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Aarrya <[email protected]>
dataset: pds.Dataset,
manifest: FileManifest,
) -> List[Tuple[pds.Fragment, int]]:
) -> List[Tuple[pds.Fragment, ReadUnit, int]]:

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.

Make Dataclass

…agments_to_read and give the new test file a main block

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Aarrya <[email protected]>
if chunk_metadata is None:
fragments.append((fragment, 0))
fragments.append(
ReadUnitFragment(fragment, ReadUnit(id=path, source=path, count=1))

@abhishekverma-ray abhishekverma-ray Sep 23, 2026 •

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.

Small robustness ask, not a bug today

Parquet reads always list by footer now, so the reader always gets a row-group list and requires_read_unit_boundaries works as intended.

But if the reader is ever handed a whole file (chunk_metadata is None), a column that asks for row-group info quietly gets index=0, count=1, num_rows=None instead. A checkpoint ID built from that would be wrong, with no error. test_whole_file_manifest_row_is_one_unit_even_with_boundaries currently locks this in.

Could we fail loudly there instead? For example, raise if a column needs boundaries and the manifest row has no row-group list. Or, at least, note in the docstring that boundaries are only available with footer listing. Either keeps a future caller from getting silent wrong IDs.

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.

Nice callout. I went with filling it from the footer when boundaries are needed.

@AarryaSaraf
AarryaSaraf marked this pull request as ready for review September 23, 2026 18:02
@AarryaSaraf
AarryaSaraf requested a review from a team as a code owner September 23, 2026 18:02
@AarryaSaraf AarryaSaraf added the go add ONLY when ready to merge, run all tests label Sep 23, 2026

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the handling of synthesized columns (such as 'path' and 'row_hash') in Ray Data's DataSourceV2. It replaces hardcoded boolean flags with a unified 'SynthesizedColumn' abstraction and introduces 'ReadUnit' to represent sub-file units of work (e.g., Parquet row groups). This allows columns requiring precise boundaries, like 'RowHashColumn', to control row group fan-out and maintain unique row hashes across sub-fragments. I have no feedback to provide as there are no review comments.

…en a column needs read unit boundaries

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Aarrya <[email protected]>
yield table, fragment.path, offset
yield table, ReadUnitPosition(
unit=fragment_to_read.unit,
unit_row_offset=offset - file_row_offset,

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.

What does unit_row_offset represent?

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.

Isn't this just table.num_rows?

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.

Rename to cumulative_unit_row_offset

Comment on lines 473 to 474
file_row_offset = fragment_to_read.file_row_offset
offset = file_row_offset

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.

This re-assignment is quite confusing

@goutamvenkat-anyscale
goutamvenkat-anyscale enabled auto-merge (squash) September 23, 2026 22:53
@goutamvenkat-anyscale
goutamvenkat-anyscale merged commit 73bdeef into ray-project:master Sep 23, 2026
7 checks passed
goutamvenkat-anyscale pushed a commit that referenced this pull request Sep 24, 2026
…checkpoint already finished (#66398)

## Description

A resumed job knows which read units it already finished: the reader
stamps
every row with its `ReadUnit.id` (#66390), so a checkpoint of the
committed
rows names them. Today the only place that knowledge could be applied is
the
read task, after `ListFiles` has read every footer and the partitioner
has
packed every row group into tasks. That re-reads footers of finished
files and
leaves a resumed job with one near-empty task per touched file.

This PR gives `ListFiles` a single input, the set of finished read unit
ids,
and drops those units at the earliest point that knows about them.
Nothing in
this PR performs checkpointing; it is the hook the checkpoint stack
(#65887)
plugs into.

### What changes

1. **`read_units.py`.** `EXCLUDED_READ_UNIT_IDS_KWARG_NAME`, the
`TaskContext.kwargs` key a resumed job sets on the `ListFiles` operator
(`MapOperator.create(map_task_kwargs=...)`). Module docstring says how
the
   ids flow.
2. **`listing/listing_utils.py`.** `list_files_for_each_block` reads the
set
   from `ctx.kwargs` and passes it to `FileIndexer.list_files`.
3. **`listing/file_indexer.py`.** `list_files` and
`_iter_file_infos_for_list` take `excluded_read_unit_ids`. A file whose
   path is in the set is dropped right after path discovery, before any
metadata fetch, so a footer-based indexer never opens it. Ids that name
   nothing are ignored.
4. **`listing/footer_file_indexer.py`.** Forwards the set to the
   `FooterReader` actors after the whole-file drop.
5. **`listing/footer_reader.py`.** `_read_and_chunk` removes row groups
named
   `<path>#rg<N>` before the predicate split and before rows are counted
toward a pushed-down limit, so a resumed job neither re-reads them nor
   stops listing early on their account.
6. **`chunkers/parquet_file_chunking_utils.py`.**
`_row_group_unit_id(path,
rg)` is the one place that spells the row-group id; the chunker and the
   footer reader both call it.
7. **Tests.** `tests/unit/datasource_v2/test_read_units.py` (new): ids
the
   reader reports round-trip through the footer reader; unknown ids are
ignored and a finished file drops; exclusion happens before predicate
and
limit accounting; the plain indexer skips whole files by path; the
footer
indexer skips whole files before any footer read and forwards row-group
ids; the listing task forwards the set from `ctx.kwargs`; excluding at
   listing time packs only the remaining work. One mock in
   `test_parquet_datasource_v2.py` accepts the new keyword.

### Before / after: resuming at 90% done

20 files of 4 row groups each, bins sized to one file. A resume with
every row
group finished except the last of the first 8 files (from
`test_excluding_units_at_listing_time_packs_only_remaining_work`):

| | footers read | read tasks |
| --- | --- | --- |
| Exclusion in the read task (today's only option) | 20 | 20, of which
12 empty and 8 at a quarter of a file |
| Exclusion in listing (this PR) | 8 | 2 full bins |

### Behavior

With no excluded ids nothing changes: `excluded_read_unit_ids` defaults
to
`None` at every layer and the footer reader's row-group range is the
same
`range(metadata.num_row_groups)` as before.

## Additional information

Not a duplicate: #65887 (checkpoint stack, `[3/4]`) drops finished files
and
row groups with its own per-file compact block threaded through the same
indexer and reader; this PR is the general hook, keyed on `ReadUnit.id`,
that
work can call instead. No other open PR touches listing-time exclusion.

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

```
pytest -q tests/unit/datasource_v2   # 140 passed
```

`ruff`, `black` and `pydoclint` at the pre-commit pins are clean;
`pyrefly`
via `ci/lint/pyrefly-check.sh` reports 59 errors, identical to the
`[3/6]`
head, none new.

Written with Claude Code; I reviewed every changed line and ran the
tests above.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Aarrya <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
dstrodtman added a commit that referenced this pull request Sep 24, 2026
## Description

Since #66357, `import ray.data` loads `pyarrow.dataset` and its native
extensions. The legacy `parquet_datasource.py` now imports
`_compute_row_hashes` from the V2 readers package at module level, and
the V2 reader modules import `pyarrow.dataset` at load time. Before
#66357, the dependency ran the other way and `ray.data` never reached
`pyarrow.dataset` on import.

This PR moves the `_compute_row_hashes` import into
`_read_batches_from`, its only caller. That matches the file's existing
function-level `pyarrow.dataset` imports. The import points at
`readers/synthesized_columns.py`, where the helper has lived since
#66390, rather than at the `file_reader` re-export. Importing from
`synthesized_columns` at module level isn't enough on its own, because
`read_units.py` also imports `pyarrow.dataset` at the top level.

It also adds `test_import_does_not_load_pyarrow_dataset` to
`python/ray/data/tests/test_import.py`. The test asserts that a fresh
driver's `import ray.data` loads no `pyarrow._dataset*` modules.

### Why this matters

The Ray docs Read the Docs build has been segfaulting intermittently, in
about 31% of builds since 2026-09-23. The crash is in native extension
init while autosummary imports RLlib → Tune → AIR → `ray.data`. A
`PYTHONFAULTHANDLER=1` traceback (#66452) puts the crash inside `from
pyarrow._dataset_parquet import ...`, which is reached from
`parquet_datasource.py` → `file_reader.py` → `import pyarrow.dataset`.
The loaded-extensions list in that traceback ends with exactly the
modules this import adds.

This change takes the crashing import off the `import ray.data` path. It
doesn't fix the underlying native crash. I couldn't reproduce it with a
bare `import pyarrow.dataset` loop in `linux/amd64` Docker: 0 of 300
runs failed, with numpy 2.2.6 and pyarrow 23.0.1 from the doc lock. So
it seems to depend on process state or on the build host. The docs build
and `requirements_compiled.txt` both pin pyarrow 23.0.1, and neither pin
changed in the failure window.

## Related issues

Related to #66357 and #66452.

## Additional information

### Not a duplicate

Searched open PRs for `_compute_row_hashes`, the DSv2 reorg series, and
lazy-import and segfault keywords. #66450 (DSv2 Reorg [4/6]) and #66201
are the nearest open PRs, and neither touches this import or
`test_import.py`.

### Tests run

These were run locally on macOS arm64, Python 3.11, pyarrow 23.0.1,
numpy 2.2.6. They used the Ray nightly wheel with `ray/data` and
`ray/tests` linked from this branch.

* `pytest python/ray/data/tests/test_import.py`: 2 passed. With the
`parquet_datasource.py` change reverted, the new test fails and lists
`pyarrow._dataset`, `_dataset_orc`, `_dataset_parquet`, and
`_dataset_parquet_encryption`.
* `pytest python/ray/data/tests/datasource/test_parquet.py -k row_hash`:
18 passed.
* `pytest python/ray/data/tests/datasource/test_parquet.py` (full
module): 242 passed, 13 skipped, 13 failed, 34 errors. Rerunning the 47
failing tests with master's `parquet_datasource.py` gave an identical
failing set, so none come from this change. They come from the local
environment:
* The S3 fixtures error in `fsspec`'s HTTP backend, because their test
dependencies aren't installed.
* Several local-path tests assert `string` columns and get
`large_string`, which is pandas/pyarrow version skew against CI's pins.

  CI is the authoritative run for this module.
* `pre-commit run --files
python/ray/data/_internal/datasource/parquet_datasource.py`: all hooks
passed, including ruff, black, pydoclint, and the import-order check.

### AI assistance

AI assistance (Claude Code) was used to investigate the import graph,
write the change and test, and draft this description. This PR stays in
draft until the submitter has reviewed every changed line.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: Douglas Strodtman <[email protected]>
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…sh flags with SynthesizedColumn objects (ray-project#66390)

## Description

`include_paths=True` adds a `path` column to every row and
`include_row_hash=True` adds `row_hash`. Each is a boolean threaded
through
`ParquetDatasourceV2` → `ParquetScanner` → `ParquetFileReader` →
`FileReader`,
and each boolean drives the same steps written out by hand: advertise
the
column in the schema, keep pyarrow from looking for it in the file, skip
it
when a projection dropped it, build it per batch, and (for `row_hash`)
scan one
row group at a time so the value can depend on the row's position. The
checkpointing work (ray-project#65885, reverted; ray-project#65887) needs a third such column
and
added a third boolean plus a 130-line copy of the read loop.

This PR replaces the booleans with `SynthesizedColumn` objects. The
reader does
the steps once for whatever columns it is given; a new column is a small
class
and touches no reader code.

### What changes

1. **`readers/synthesized_columns.py` (new).** `SynthesizedColumn` with
`name`, `type`, `requires_read_unit_boundaries` and `compute(position,
num_rows)`; `ReadUnitPosition` (the read unit a table of rows came from
   plus its row offsets); `PathColumn` and `RowHashColumn`.
`_compute_row_hashes` and the two column-name constants move here from
   `file_reader.py`, which re-exports them for the legacy datasource.
2. **`read_units.py` (new).** `ReadUnit`: the piece of a file a reader
scans on
its own, a row group or a whole file, with a stable id (`<path>#rg<i>`),
   its index, the file's group count and its row count. This is what a
   checkpoint ID column needs to name a row.
3. **`parquet_datasource_v2.py`.** The two flags become a tuple of
column
objects; `infer_schema` appends each column's name and type in one loop.
   The unused `include_paths` property is gone.
4. **`scanners/parquet_scanner.py`.** One `synthesized_columns` field
replaces
the two booleans; `read_schema` loops over it with the same skip rules.
5. **`readers/file_reader.py`.** Constructor takes the tuple. The
pyarrow
schema strips the configured column names. `_get_fragments_to_read`
returns
`(fragment, ReadUnit, file_row_offset)` and the read loop yields
`(table,
ReadUnitPosition)`. The `row_hash` block becomes a loop over the
columns; the
`path` line leaves the partition block because `PathColumn` goes through
the
   same loop.
6. **`readers/parquet_file_reader.py`** and
**`chunkers/parquet_file_chunking_utils.py`.** Per-row-group fan-out is
keyed on "any column requires boundaries" instead of `include_row_hash`,
and
each sub-fragment comes back with its `ReadUnit`. Same footer read, same
   condition.
7. **Tests.** `tests/unit/datasource_v2/test_synthesized_columns.py`
(new):
fan-out is one unit per file unless a column needs boundaries, a
whole-file
   manifest row stays one unit, `row_hash` is identical whole-file vs
per-row-group, a same-named file column is replaced, `read_schema`
respects
   projection. Three asserts in `test_parquet_datasource_v2.py` updated.

### Before / after: adding a column

Before, ray-project#65885 added `generated_id_column` as a third boolean: +160
lines
across four `datasource_v2` files, 129 of them a `ParquetFileReader`
override
duplicating `_read_fragments_sequential`. After, the same column is one
class
next to `RowHashColumn` and no reader change:

```python
class CheckpointIdColumn(SynthesizedColumn):
    name = ...; type = GENERATED_ID_COLUMN_TYPE
    requires_read_unit_boundaries = True

    def compute(self, position, num_rows):
        u = position.unit
        return get_generated_id_column(u.source, u.index, u.count, u.num_rows,
                                       position.unit_row_offset, num_rows)
```

### Behavior

Row order, appended-column order (partitions, `path`, `row_hash`), the
row-hash
arithmetic, retry scoping and the fan-out condition are unchanged. One
intended fix: for a file that already has a non-string column named
`path`,
read with `include_paths=True`, `ds.schema()` now says `path: string`,
which is
what the blocks always carried. Related to that, the schema handed to
pyarrow
strips `path` only when `PathColumn` is configured, where it used to
strip it
unconditionally.

## Additional information

Not a duplicate: no open PR introduces column objects or read units.
ray-project#65887
(checkpoint skipping) edits the same reader files with its own booleans;
this
PR is the seam that work can move onto. ray-project#65989 (mine) is about
predicates
naming a synthesized column and is independent.

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

```
pytest -q tests/unit/datasource_v2   # 133 passed
```

`ruff`, `black` and `pydoclint` at the pre-commit pins are clean;
`pyrefly`
via `ci/lint/pyrefly-check.sh` reports 59 errors against 61 on the base,
none
new.

Written with Claude Code; I reviewed every changed line and ran the
tests above.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Aarrya <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…checkpoint already finished (ray-project#66398)

## Description

A resumed job knows which read units it already finished: the reader
stamps
every row with its `ReadUnit.id` (ray-project#66390), so a checkpoint of the
committed
rows names them. Today the only place that knowledge could be applied is
the
read task, after `ListFiles` has read every footer and the partitioner
has
packed every row group into tasks. That re-reads footers of finished
files and
leaves a resumed job with one near-empty task per touched file.

This PR gives `ListFiles` a single input, the set of finished read unit
ids,
and drops those units at the earliest point that knows about them.
Nothing in
this PR performs checkpointing; it is the hook the checkpoint stack
(ray-project#65887)
plugs into.

### What changes

1. **`read_units.py`.** `EXCLUDED_READ_UNIT_IDS_KWARG_NAME`, the
`TaskContext.kwargs` key a resumed job sets on the `ListFiles` operator
(`MapOperator.create(map_task_kwargs=...)`). Module docstring says how
the
   ids flow.
2. **`listing/listing_utils.py`.** `list_files_for_each_block` reads the
set
   from `ctx.kwargs` and passes it to `FileIndexer.list_files`.
3. **`listing/file_indexer.py`.** `list_files` and
`_iter_file_infos_for_list` take `excluded_read_unit_ids`. A file whose
   path is in the set is dropped right after path discovery, before any
metadata fetch, so a footer-based indexer never opens it. Ids that name
   nothing are ignored.
4. **`listing/footer_file_indexer.py`.** Forwards the set to the
   `FooterReader` actors after the whole-file drop.
5. **`listing/footer_reader.py`.** `_read_and_chunk` removes row groups
named
   `<path>#rg<N>` before the predicate split and before rows are counted
toward a pushed-down limit, so a resumed job neither re-reads them nor
   stops listing early on their account.
6. **`chunkers/parquet_file_chunking_utils.py`.**
`_row_group_unit_id(path,
rg)` is the one place that spells the row-group id; the chunker and the
   footer reader both call it.
7. **Tests.** `tests/unit/datasource_v2/test_read_units.py` (new): ids
the
   reader reports round-trip through the footer reader; unknown ids are
ignored and a finished file drops; exclusion happens before predicate
and
limit accounting; the plain indexer skips whole files by path; the
footer
indexer skips whole files before any footer read and forwards row-group
ids; the listing task forwards the set from `ctx.kwargs`; excluding at
   listing time packs only the remaining work. One mock in
   `test_parquet_datasource_v2.py` accepts the new keyword.

### Before / after: resuming at 90% done

20 files of 4 row groups each, bins sized to one file. A resume with
every row
group finished except the last of the first 8 files (from
`test_excluding_units_at_listing_time_packs_only_remaining_work`):

| | footers read | read tasks |
| --- | --- | --- |
| Exclusion in the read task (today's only option) | 20 | 20, of which
12 empty and 8 at a quarter of a file |
| Exclusion in listing (this PR) | 8 | 2 full bins |

### Behavior

With no excluded ids nothing changes: `excluded_read_unit_ids` defaults
to
`None` at every layer and the footer reader's row-group range is the
same
`range(metadata.num_row_groups)` as before.

## Additional information

Not a duplicate: ray-project#65887 (checkpoint stack, `[3/4]`) drops finished files
and
row groups with its own per-file compact block threaded through the same
indexer and reader; this PR is the general hook, keyed on `ReadUnit.id`,
that
work can call instead. No other open PR touches listing-time exclusion.

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

```
pytest -q tests/unit/datasource_v2   # 140 passed
```

`ruff`, `black` and `pydoclint` at the pre-commit pins are clean;
`pyrefly`
via `ci/lint/pyrefly-check.sh` reports 59 errors, identical to the
`[3/6]`
head, none new.

Written with Claude Code; I reviewed every changed line and ran the
tests above.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Aarrya <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…6463)

## Description

Since ray-project#66357, `import ray.data` loads `pyarrow.dataset` and its native
extensions. The legacy `parquet_datasource.py` now imports
`_compute_row_hashes` from the V2 readers package at module level, and
the V2 reader modules import `pyarrow.dataset` at load time. Before
ray-project#66357, the dependency ran the other way and `ray.data` never reached
`pyarrow.dataset` on import.

This PR moves the `_compute_row_hashes` import into
`_read_batches_from`, its only caller. That matches the file's existing
function-level `pyarrow.dataset` imports. The import points at
`readers/synthesized_columns.py`, where the helper has lived since
ray-project#66390, rather than at the `file_reader` re-export. Importing from
`synthesized_columns` at module level isn't enough on its own, because
`read_units.py` also imports `pyarrow.dataset` at the top level.

It also adds `test_import_does_not_load_pyarrow_dataset` to
`python/ray/data/tests/test_import.py`. The test asserts that a fresh
driver's `import ray.data` loads no `pyarrow._dataset*` modules.

### Why this matters

The Ray docs Read the Docs build has been segfaulting intermittently, in
about 31% of builds since 2026-09-23. The crash is in native extension
init while autosummary imports RLlib → Tune → AIR → `ray.data`. A
`PYTHONFAULTHANDLER=1` traceback (ray-project#66452) puts the crash inside `from
pyarrow._dataset_parquet import ...`, which is reached from
`parquet_datasource.py` → `file_reader.py` → `import pyarrow.dataset`.
The loaded-extensions list in that traceback ends with exactly the
modules this import adds.

This change takes the crashing import off the `import ray.data` path. It
doesn't fix the underlying native crash. I couldn't reproduce it with a
bare `import pyarrow.dataset` loop in `linux/amd64` Docker: 0 of 300
runs failed, with numpy 2.2.6 and pyarrow 23.0.1 from the doc lock. So
it seems to depend on process state or on the build host. The docs build
and `requirements_compiled.txt` both pin pyarrow 23.0.1, and neither pin
changed in the failure window.

## Related issues

Related to ray-project#66357 and ray-project#66452.

## Additional information

### Not a duplicate

Searched open PRs for `_compute_row_hashes`, the DSv2 reorg series, and
lazy-import and segfault keywords. ray-project#66450 (DSv2 Reorg [4/6]) and ray-project#66201
are the nearest open PRs, and neither touches this import or
`test_import.py`.

### Tests run

These were run locally on macOS arm64, Python 3.11, pyarrow 23.0.1,
numpy 2.2.6. They used the Ray nightly wheel with `ray/data` and
`ray/tests` linked from this branch.

* `pytest python/ray/data/tests/test_import.py`: 2 passed. With the
`parquet_datasource.py` change reverted, the new test fails and lists
`pyarrow._dataset`, `_dataset_orc`, `_dataset_parquet`, and
`_dataset_parquet_encryption`.
* `pytest python/ray/data/tests/datasource/test_parquet.py -k row_hash`:
18 passed.
* `pytest python/ray/data/tests/datasource/test_parquet.py` (full
module): 242 passed, 13 skipped, 13 failed, 34 errors. Rerunning the 47
failing tests with master's `parquet_datasource.py` gave an identical
failing set, so none come from this change. They come from the local
environment:
* The S3 fixtures error in `fsspec`'s HTTP backend, because their test
dependencies aren't installed.
* Several local-path tests assert `string` columns and get
`large_string`, which is pandas/pyarrow version skew against CI's pins.

  CI is the authoritative run for this module.
* `pre-commit run --files
python/ray/data/_internal/datasource/parquet_datasource.py`: all hooks
passed, including ruff, black, pydoclint, and the import-order check.

### AI assistance

AI assistance (Claude Code) was used to investigate the import graph,
write the change and test, and draft this description. This PR stays in
draft until the submitter has reviewed every changed line.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: Douglas Strodtman <[email protected]>
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
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