Skip to content

[Data] Keep the filter when a predicate names a synthesized column - #65989

Closed
AarryaSaraf wants to merge 1 commit into
ray-project:masterfrom
AarryaSaraf:data-fix-synthesized-column-filter
Closed

AarryaSaraf wants to merge 1 commit into
ray-project:masterfrom
AarryaSaraf:data-fix-synthesized-column-filter

Conversation

@AarryaSaraf

@AarryaSaraf AarryaSaraf commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Why

include_paths=True / include_row_hash=True add columns after the read, so they
are in the dataset schema but in no Parquet file. ReadFiles.apply_predicate pushes
any predicate at the scanner regardless, and PredicatePushdown then deletes the
Filter that would have evaluated it. PyArrow cannot bind the column, so the read
raises:

ds = ray.data.read_parquet(root, include_paths=True)
ds.filter(expr=col("path") == one_file).take_all()
# ArrowInvalid: No match for FieldRef.Name(path) in x: int64

The same filter written as a UDF works, so the expression API is strictly worse here
than the callable one.

What changes

A scanner now reports which columns it manufactures after the scan:
ParquetScanner.synthesized_columns is {"path"} under include_paths=True,
{"row_hash"} under include_row_hash=True.

apply_predicate uses that to send each conjunct to the one place that can evaluate
it:

conjunct references goes to why
data columns (x > 1) the PyArrow scanner in the file; prunes row groups
partition columns (year == "2020") prune_manifest in the path; prunes whole files
synthesized columns (path == ...) a Filter above the read does not exist until after the read

Splitting rather than giving up on the whole predicate is what keeps this cheap. On
(col("x") > 1) & (col("path") == target):

residual Filter holds scanner predicate
master (Filter deleted) x, path -> ArrowInvalid
this PR path x

x > 1 still reaches the scanner and keeps its row-group pruning; only path
stays above.

When nothing in the predicate is pushable — col("path") == target on its own —
apply_predicate returns the read operator it was given, unmodified. That is the
existing way an operator declines a pushdown: PredicatePushdown compares the
returned operator to the one it passed in, sees they are the same object, and leaves
the Filter where it was.

Not included: pruning files by path at the manifest level. path is known per file
at listing time, so an exact-match predicate could drop files before opening them.
That is a new capability rather than a bug fix, and it needs the same limit wiring as
partition pruning (listing must not stop early when the reader will discard files), so
it belongs in its own PR.

Test

test_filter_on_include_paths_column and test_filter_mixing_synthesized_and_data_column
in python/ray/data/tests/test_predicate_pushdown.py. The first fails on master with
the ArrowInvalid above; the second pins the split, so it also fails against an
all-or-nothing version of this fix.

pytest python/ray/data/tests/test_predicate_pushdown.py \
       python/ray/data/tests/unit/test_parquet_predicate_split.py
85 passed

Not a duplicate: gh pr list --search "predicate pushdown" / "include_paths" shows
no open PR touching apply_predicate or synthesized-column handling.

AI assistance was used to write this change.

@AarryaSaraf AarryaSaraf added data Ray Data-related issues go add ONLY when ready to merge, run all tests labels Sep 8, 2026
@AarryaSaraf
AarryaSaraf force-pushed the data-fix-synthesized-column-filter branch from f6cd949 to de29065 Compare September 8, 2026 23:23
@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had
any activity for 14 days. It will be closed in another 14 days if no further activity occurs.
Thank you for your contributions.

You can always ask for help on our discussion forum or Ray's public slack channel.

If you'd like to keep this open, just leave any comment, and the stale label will be removed.

@github-actions github-actions Bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Sep 23, 2026
goutamvenkat-anyscale pushed a commit that referenced this pull request Sep 23, 2026
…sh flags with SynthesizedColumn objects (#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 (#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:

```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.
#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](https://claude.com/claude-code)

---------

Signed-off-by: Aarrya <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
goutamvenkat-anyscale pushed a commit that referenced this pull request Sep 25, 2026
…let it reach scanners without filter pushdown (#66478)

## Description

Partition pruning drops whole files by the partition values in their
paths.
It lived on `ArrowFileScanner`, so only PyArrow Dataset formats had it,
and
`ReadFiles.apply_predicate` required filter pushdown, so a scanner
without
it never received a predicate at all. Partition values come from paths
and
the `Partitioning` spec, not from file contents, so the pruning is the
same
for every file format. This PR moves it to `FileScanner` and lets
partition
conjuncts reach a scanner that has nothing else to push.

### What changes

1. **`scanners/file_scanner.py`.** `FileScanner` becomes a
`SupportsPartitionPruning`. The `partitioning` and `partition_predicate`
   fields and the five pruning members move here from `ArrowFileScanner`
   unchanged.
2. **`scanners/arrow_file_scanner.py`.** Loses them; keeps filter,
column
   and limit pushdown.
3. **`logical/operators/read_operator.py`.**
`supports_predicate_pushdown`
   accepts either mixin. In `apply_predicate`, data conjuncts go to
   `push_filters` only when the scanner has it and otherwise stay in the
   `Filter`; when nothing was pushed it returns `self` so the original
   `Filter` is kept.
4. **Comments** in `scanner.py`, `plan_read_files_op.py`,
`file_pruners.py`
   and `logical_optimizers.py` now name `FileScanner`.
5. **`tests/unit/datasource_v2/test_file_scanner.py`** (new): a scanner
with no pushdown of its own takes a partition predicate, data conjuncts
   stay in a `Filter` above the read, nothing-to-push keeps the original
   operator, listing derives the same pruner as the reader, and
   `prune_input_split` drops files by path.

```mermaid
flowchart TD
    P["ReadFiles.apply_predicate(expr)"] --> S["split expr by partition columns"]
    S -->|partition conjuncts| PP["scanner.prune_partitions"]
    S -->|data conjuncts, scanner pushes filters| PF["scanner.push_filters"]
    S -->|data conjuncts, no filter pushdown| F["stay in Filter above the read"]
    PP --> N{"anything pushed?"}
    PF --> N
    N -->|no| K["return self: original Filter kept"]
    N -->|yes| R["new ReadFiles, residual Filter if any"]
```

`ParquetScanner` and every other `ArrowFileScanner` behave as before:
same
members, inherited one level up.

## Additional information

Not a duplicate: no open PR touches partition pruning or the `ReadFiles`
pushdown gate. #65989 (mine) is about synthesized-column conjuncts and
is
independent. `[4/6]` #66450 is parked; this PR sits directly on
`master`.

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

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

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

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

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

---------

Signed-off-by: Aarrya <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
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
…let it reach scanners without filter pushdown (ray-project#66478)

## Description

Partition pruning drops whole files by the partition values in their
paths.
It lived on `ArrowFileScanner`, so only PyArrow Dataset formats had it,
and
`ReadFiles.apply_predicate` required filter pushdown, so a scanner
without
it never received a predicate at all. Partition values come from paths
and
the `Partitioning` spec, not from file contents, so the pruning is the
same
for every file format. This PR moves it to `FileScanner` and lets
partition
conjuncts reach a scanner that has nothing else to push.

### What changes

1. **`scanners/file_scanner.py`.** `FileScanner` becomes a
`SupportsPartitionPruning`. The `partitioning` and `partition_predicate`
   fields and the five pruning members move here from `ArrowFileScanner`
   unchanged.
2. **`scanners/arrow_file_scanner.py`.** Loses them; keeps filter,
column
   and limit pushdown.
3. **`logical/operators/read_operator.py`.**
`supports_predicate_pushdown`
   accepts either mixin. In `apply_predicate`, data conjuncts go to
   `push_filters` only when the scanner has it and otherwise stay in the
   `Filter`; when nothing was pushed it returns `self` so the original
   `Filter` is kept.
4. **Comments** in `scanner.py`, `plan_read_files_op.py`,
`file_pruners.py`
   and `logical_optimizers.py` now name `FileScanner`.
5. **`tests/unit/datasource_v2/test_file_scanner.py`** (new): a scanner
with no pushdown of its own takes a partition predicate, data conjuncts
   stay in a `Filter` above the read, nothing-to-push keeps the original
   operator, listing derives the same pruner as the reader, and
   `prune_input_split` drops files by path.

```mermaid
flowchart TD
    P["ReadFiles.apply_predicate(expr)"] --> S["split expr by partition columns"]
    S -->|partition conjuncts| PP["scanner.prune_partitions"]
    S -->|data conjuncts, scanner pushes filters| PF["scanner.push_filters"]
    S -->|data conjuncts, no filter pushdown| F["stay in Filter above the read"]
    PP --> N{"anything pushed?"}
    PF --> N
    N -->|no| K["return self: original Filter kept"]
    N -->|yes| R["new ReadFiles, residual Filter if any"]
```

`ParquetScanner` and every other `ArrowFileScanner` behave as before:
same
members, inherited one level up.

## Additional information

Not a duplicate: no open PR touches partition pruning or the `ReadFiles`
pushdown gate. ray-project#65989 (mine) is about synthesized-column conjuncts and
is
independent. `[4/6]` ray-project#66450 is parked; this PR sits directly on
`master`.

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

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

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

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

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

---------

Signed-off-by: Aarrya <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

This pull request has been automatically closed because there has been no more activity in the 14 days
since being marked stale.

Please feel free to reopen or open a new pull request if you'd still like this to be addressed.

Again, you can always ask for help on our discussion forum or Ray's public slack channel.

Thanks again for your contribution!

@github-actions github-actions Bot closed this Oct 7, 2026
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 stale The issue is stale. It will be closed within 7 days unless there are further conversation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant