Repository navigation
[Data] Keep the filter when a predicate names a synthesized column - #65989
Closed
AarryaSaraf wants to merge 1 commit into
Closed
AarryaSaraf wants to merge 1 commit into
AarryaSaraf wants to merge 1 commit into
Conversation
Signed-off-by: Aarrya <[email protected]>
AarryaSaraf
force-pushed
the
data-fix-synthesized-column-filter
branch
from
September 8, 2026 23:23
f6cd949 to
de29065
Compare
|
This pull request has been automatically marked as stale because it has not had 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. |
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]>
|
This pull request has been automatically closed because there has been no more activity in the 14 days 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! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
include_paths=True/include_row_hash=Trueadd columns after the read, so theyare in the dataset schema but in no Parquet file.
ReadFiles.apply_predicatepushesany predicate at the scanner regardless, and
PredicatePushdownthen deletes theFilterthat would have evaluated it. PyArrow cannot bind the column, so the readraises:
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_columnsis{"path"}underinclude_paths=True,{"row_hash"}underinclude_row_hash=True.apply_predicateuses that to send each conjunct to the one place that can evaluateit:
x > 1)year == "2020")prune_manifestpath == ...)Filterabove the readSplitting rather than giving up on the whole predicate is what keeps this cheap. On
(col("x") > 1) & (col("path") == target):Filterholdsx,path->ArrowInvalidpathxx > 1still reaches the scanner and keeps its row-group pruning; onlypathstays above.
When nothing in the predicate is pushable —
col("path") == targeton its own —apply_predicatereturns the read operator it was given, unmodified. That is theexisting way an operator declines a pushdown:
PredicatePushdowncompares thereturned operator to the one it passed in, sees they are the same object, and leaves
the
Filterwhere it was.Not included: pruning files by
pathat the manifest level.pathis known per fileat 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_columnandtest_filter_mixing_synthesized_and_data_columnin
python/ray/data/tests/test_predicate_pushdown.py. The first fails on master withthe
ArrowInvalidabove; the second pins the split, so it also fails against anall-or-nothing version of this fix.
Not a duplicate:
gh pr list --search "predicate pushdown"/"include_paths"showsno open PR touching
apply_predicateor synthesized-column handling.AI assistance was used to write this change.