Repository navigation
[Data] Bind the generated ID column at plan time, not in read_parquet() - #67157
Conversation
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]>
There was a problem hiding this comment.
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.
… 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]>
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]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Reviewed by Cursor Bugbot for commit f1c361b. Configure here.
…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]>
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]>
…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]>

Description
CheckpointConfig(generated_id_column=...)can be set on a dataset afterread_parquet()built it — Ray Train'sDatasetManagerdoes exactly this (see #66800). Previouslyread_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:
BindGeneratedIdColumn, run inLogicalOptimizer._post_optimize(after the rule loop, beforeDeriveListFilesPushdown): adds the column to theParquetScannerand toProjects 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_columnsplumbing are removed._validate_generated_id_plannow runs on every generated-ID plan and fails at planning if a scanner is missing the column.schema()/columns()agree with execution:_base_schemaappliesBindGeneratedIdColumnwhen 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,
DatasetManagerderives theCheckpointConfigfrom fit-time state — the restoredstate_dictand its restore filter — and stamps it onto the user's already-built dataset. That config cannot exist yet when the user callsread_parquet(), and since each dataset snapshots its ownDataContextat 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🟦 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 --> COMPUTETesting
Notes
🤖 Generated with Claude Code