Skip to content

[Data] Bind the generated ID column at plan time, not in read_parquet() - #67157

Merged
goutamvenkat-anyscale merged 5 commits into
ray-project:masterfrom
goutamvenkat-anyscale:goutam/bind-generated-id-at-plan-time
Oct 23, 2026
Merged

goutamvenkat-anyscale merged 5 commits into
ray-project:masterfrom
goutamvenkat-anyscale:goutam/bind-generated-id-at-plan-time

Conversation

@goutamvenkat-anyscale

@goutamvenkat-anyscale goutamvenkat-anyscale commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Description

CheckpointConfig(generated_id_column=...) can be set on a dataset after read_parquet() built it — Ray Train's DatasetManager does exactly this (see #66800). Previously read_parquet() snapshotted the config at call time and baked the generated ID column into the datasource constructor, so a config set afterwards never produced the column and checkpointing silently recorded nothing.

This PR moves the binding to plan time:

  • New logical rule BindGeneratedIdColumn, run in LogicalOptimizer._post_optimize (after the rule loop, before DeriveListFilesPushdown): adds the column to the ParquetScanner and to Projects built before the config was set.
  • read_parquet() no longer binds the column; its call-time config snapshot and the _add_generated_id_column / extra_synthesized_columns plumbing are removed.
  • _validate_generated_id_plan now runs on every generated-ID plan and fails at planning if a scanner is missing the column.
  • schema() / columns() agree with execution: _base_schema applies BindGeneratedIdColumn when the configured column is missing from its answer (metadata is inferred from the unoptimized DAG, which doesn't run the rule), including over a schema cached before the config was set.

ID values are unchanged (GeneratedIdColumn.compute() in the read tasks); only where the column attaches to the plan moved.

Why plan time: who knows what, when

This change exists for Ray Train's mid-epoch resumption (#66800): there, DatasetManager derives the CheckpointConfig from fit-time state — the restored state_dict and its restore filter — and stamps it onto the user's already-built dataset. That config cannot exist yet when the user calls read_parquet(), and since each dataset snapshots its own DataContext at build time, setting it globally afterwards would never reach an already-built dataset either. The only ordering that works is the one #66800 uses — stamp the built dataset — with Ray Data picking the config up when the executed plan is optimized:

sequenceDiagram
    participant U as user code
    participant T as Ray Train (DatasetManager)
    participant D as dataset's DataContext / plan

    U->>D: ds = ray.data.read_parquet(...)
    Note over D: DataContext.copy() snapshot — checkpoint_config: None
    U->>T: trainer.fit(datasets={"train": ds})
    rect rgba(66, 135, 245, 0.25)
        T->>T: rank 0 requests its shard: get_dataset_shard("train", state_dict=...)
        T->>D: ds.context.checkpoint_config = CheckpointConfig(generated_id_column=..., restore filter)
    end
    rect rgba(235, 140, 60, 0.3)
        loop each epoch
            D->>D: optimize plan — BindGeneratedIdColumn binds the column — then execute
        end
    end
Loading

🟦 Train's mid-epoch-resume wiring (PR 66800) · 🟧 this PR (plan-time binding) · unshaded steps are pre-existing behavior.

New flow

flowchart TB
    subgraph build["Dataset build (lazy)"]
        RP["read_parquet()<br/>builds ListFiles → ReadFiles<br/><i>no column decision</i>"]
        CFG["ds.context.checkpoint_config = CheckpointConfig(generated_id_column=...)<br/><i>at any point before execution</i>"]
    end
    subgraph opt["Execution: LogicalOptimizer"]
        LOOP["Ruleset loop<br/>(projection pushdown, ...)"]
        BIND["<b>BindGeneratedIdColumn</b><br/>reads plan.context.checkpoint_config,<br/>appends GeneratedIdColumn to the ParquetScanner,<br/>keeps it through earlier-built Projects"]
        DLP["DeriveListFilesPushdown<br/>listing sees the bound projection"]
    end
    subgraph plan["Planner"]
        VAL["_validate_generated_id_plan<br/>every source is a V2 Parquet read<br/><b>and carries the column</b>, else<br/>InvalidCheckpointingConfig at planning"]
    end
    subgraph exec["Read tasks"]
        COMPUTE["GeneratedIdColumn.compute()<br/>stamps (file, row group, row offset)<br/>per batch — unchanged"]
    end
    RP --> CFG --> LOOP --> BIND --> DLP --> VAL --> COMPUTE
Loading

Testing

pytest python/ray/data/tests/unit/datasource_v2/test_bind_generated_id_column.py \
       python/ray/data/tests/unit/datasource_v2/test_generated_id_column.py
# 22 passed

cd python/ray/data/tests && pytest test_checkpoint.py -k "generated_id"
# 26 passed (includes new tests: config set after the dataset is built, with
# select_columns / with_column / streaming_split, and plan-validation failures)

Notes

🤖 Generated with Claude Code

CheckpointConfig(generated_id_column=...) can be set on a dataset after
read_parquet() built it (Ray Train's DatasetManager does this), in which
case the column was never generated: read_parquet() snapshotted the config
at call time and baked the column into the datasource constructor.

Move the binding to a logical rule, BindGeneratedIdColumn, that runs when
the plan is optimized. It reads the config of the plan being executed,
appends the GeneratedIdColumn to the ParquetScanner, and keeps the column
through Projects built before the config was set. The planner now
validates every generated-ID plan (not only restoring ones) and checks
the scanner actually carries the column, so a missing column fails at
planning instead of at the write.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Goutam <[email protected]>
@goutamvenkat-anyscale
goutamvenkat-anyscale requested a review from a team as a code owner October 19, 2026 08:29

@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 how the generated ID column is added to Parquet reads by shifting the responsibility from the initial read API to a new logical optimizer rule, BindGeneratedIdColumn. This rule runs during post-optimization to bind the generated ID column to Parquet reads and ensure downstream Project operators retain it, allowing the checkpoint configuration to be set on a dataset after it has been built. Corresponding unit and integration tests have been added and updated to verify this new behavior. I have no feedback to provide as there are no review comments.

@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.

Stale Bugbot comment from a previous run.

@ray-gardener ray-gardener Bot added the data Ray Data-related issues label Oct 19, 2026
@goutamvenkat-anyscale goutamvenkat-anyscale added the go add ONLY when ready to merge, run all tests label Oct 19, 2026
… errors

schema()/columns() infer from the unoptimized DAG, so they omitted the
generated ID column that BindGeneratedIdColumn adds at execution.
_base_schema now applies the rule when the configured column is missing
from its answer, also healing a schema cached before the config was set.

Also fixes the pyrefly CI errors: narrow Optional[str] into the rule's
closure, and replace untyped scanner access in the unit tests.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Goutam <[email protected]>

@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.

Stale Bugbot comment from a previous run.

Comment thread python/ray/data/dataset.py Resolved
The bound plan's infer_schema() is None for UDF plans, so _base_schema
was discarding valid cached schemas (a pandas schema carrying the
column, an Arrow schema whose UDF dropped it) and re-triggering the
fetch-by-execution path on every schema() call. Duck-type the names
check instead of requiring pa.Schema, and keep the current answer when
the bound re-inference returns None.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Goutam <[email protected]>

@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 and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit f1c361b. Configure here.

Comment thread python/ray/data/dataset.py Resolved
…onfigured

A UDF plan's only schema source is executing a block, and a schema fetched
before checkpoint_config was set never ran BindGeneratedIdColumn — but it
looked identical to one whose UDF legitimately dropped the column, so the
keep-known-schema guard served it forever while execution stamped the
column into every row.

Stamp each cached schema with the generated_id_column binding it was
obtained under. A cached schema that lacks the column and was written
under a different binding is a miss, so schema() re-fetches it with the
rule active; one written under the current binding (the UDF dropped it)
is still served without refetch loops. Materialized bundles keep serving
their schema unconditionally: iteration returns exactly that data.

Co-Authored-By: Claude Fable 5 <[email protected]>
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.

Just one comment!

Comment thread python/ray/data/dataset.py Resolved
Both set_schema callers record the generated-ID binding, so get_schema
can require strict equality instead of only invalidating when the new
column is missing from the cached schema. This also invalidates the
cache when checkpoint_config is cleared, which previously kept serving
a schema with a generated ID column execution no longer produces.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Goutam <[email protected]>
@goutamvenkat-anyscale
goutamvenkat-anyscale enabled auto-merge (squash) October 23, 2026 21:25
@goutamvenkat-anyscale
goutamvenkat-anyscale merged commit 98e7143 into ray-project:master Oct 23, 2026
7 checks passed
@goutamvenkat-anyscale
goutamvenkat-anyscale deleted the goutam/bind-generated-id-at-plan-time branch October 23, 2026 22:55
goutamvenkat-anyscale pushed a commit that referenced this pull request Nov 11, 2026
…67164)

## Update after #67157

PR #67157 has changed how generated ID columns are attached to Parquet
reads. Instead of adding the generated ID column when read_parquet()
constructs ParquetDatasourceV2, it is now bound at plan time by
BindGeneratedIdColumn, superseding the original implementation in this
PR.

That change also prevents the silent overwrite reported in #67002: a
configuration such as include_paths=True with generated_id_column="path"
is now rejected during plan optimization. However, current master
handles the collision through the generic physical-column check and
reports:

```
Column 'path' already exists in the Parquet data...
```

In this case, path is actually a synthesized column created by
include_paths=True, not a physical Parquet column. The same applies to
row_hash.

This PR therefore no longer changes whether the collision is accepted or
rejected. Instead, it explicitly distinguishes generated-ID collisions
with synthesized columns from physical Parquet-column conflicts. This
makes the validation reflect the actual configuration error, gives users
actionable guidance, and adds regression coverage so future generated-ID
or synthesized-column changes preserve this behavior.

## Change

- Detect generated-ID name collisions with existing synthesized columns
in BindGeneratedIdColumn.
- Report synthesized-column collisions separately from physical
Parquet-column collisions.
- Preserve the existing physical-column collision behavior.
- Add regression coverage for:
  - include_paths=True with generated_id_column="path";
  - include_row_hash=True with generated_id_column="row_hash"; and
  - a non-conflicting path and generated_id configuration.

## Current master / This PR

Case | Current master | This PR
-- | -- | --
include_paths=True + generated ID named path | Rejected, but reported as
a physical Parquet-column collision | Rejected explicitly as a
synthesized-column collision
include_row_hash=True + generated ID named row_hash | Rejected, but
reported as a physical Parquet-column collision | Rejected explicitly as
a synthesized-column collision

## Related issues

Follow-up to #67002. The original silent-overwrite behavior is already
prevented by #67157;
this PR addresses the remaining collision-classification behavior.

Related to #67157.

## Validation

- Added regression tests for generated-ID collisions with both
PathColumn and RowHashColumn.
- Added a control test confirming distinct synthesized-column names
continue to coexist.
- Reproduced the public read_parquet(include_paths=True) case against
current master, where execution reports the synthesized path column as
if it came from the physical Parquet data.
- Verified the updated implementation reports the same configuration
explicitly as a synthesized-column collision.

Signed-off-by: Yin-1022 <[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.

2 participants