-
Notifications
You must be signed in to change notification settings - Fork 212
fix(compiler): support columns_added and columns_removed in processor config (#394) #943
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -18,11 +18,40 @@ | |||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| def compile_data_designer_config(config: DataDesignerConfig, resource_provider: ResourceProvider) -> DataDesignerConfig: | ||||||||||||||||||||||||||||||||
| _resolve_and_add_seed_columns(config, resource_provider.seed_reader) | ||||||||||||||||||||||||||||||||
| _apply_processor_column_modifications(config) | ||||||||||||||||||||||||||||||||
| _add_internal_row_id_column_if_needed(config) | ||||||||||||||||||||||||||||||||
| _validate(config) | ||||||||||||||||||||||||||||||||
| return config | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| def _apply_processor_column_modifications(config: DataDesignerConfig) -> None: | ||||||||||||||||||||||||||||||||
| """Adjusts columns according to columns_added and columns_removed declared by processors.""" | ||||||||||||||||||||||||||||||||
| for processor in config.processors or []: | ||||||||||||||||||||||||||||||||
| if processor.columns_removed: | ||||||||||||||||||||||||||||||||
| current_columns = {col.name for col in config.columns} | ||||||||||||||||||||||||||||||||
| for col_name in processor.columns_removed: | ||||||||||||||||||||||||||||||||
| if col_name not in current_columns: | ||||||||||||||||||||||||||||||||
| raise InvalidConfigError( | ||||||||||||||||||||||||||||||||
| f"🛑 Processor '{processor.name}' cannot remove column '{col_name}' because it does not exist." | ||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||
| removed_set = set(processor.columns_removed) | ||||||||||||||||||||||||||||||||
| config.columns = [col for col in config.columns if col.name not in removed_set] | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if processor.columns_added: | ||||||||||||||||||||||||||||||||
| if config.seed_config is None: | ||||||||||||||||||||||||||||||||
| raise InvalidConfigError( | ||||||||||||||||||||||||||||||||
| f"🛑 Processor '{processor.name}' specifies 'columns_added', but no seed dataset is configured." | ||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||
| existing_columns = {col.name for col in config.columns} | ||||||||||||||||||||||||||||||||
| for col_name in processor.columns_added: | ||||||||||||||||||||||||||||||||
| if col_name in existing_columns: | ||||||||||||||||||||||||||||||||
| raise InvalidConfigError( | ||||||||||||||||||||||||||||||||
| f"🛑 Processor '{processor.name}' adds column '{col_name}' which collides with an existing column." | ||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||
| config.columns.append(SeedDatasetColumnConfig(name=col_name)) | ||||||||||||||||||||||||||||||||
|
Comment on lines
+45
to
+51
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Knowledge Base Used: Workflow compilation and execution Prompt To Fix With AIThis is a comment left during a code review.
Path: packages/data-designer-engine/src/data_designer/engine/compiler.py
Line: 45-51
Comment:
**Repeated additions bypass collision checks**
`existing_columns` is captured only once before this loop. With `columns_added=["state", "state"]`, both checks pass and two columns named `state` are appended. Static validation does not reject the duplicate, so execution-graph construction later tries to register `state` twice and raises `ValueError`.
```suggestion
existing_columns = {col.name for col in config.columns}
for col_name in processor.columns_added:
if col_name in existing_columns:
raise InvalidConfigError(
f"🛑 Processor '{processor.name}' adds column '{col_name}' which collides with an existing column."
)
config.columns.append(SeedDatasetColumnConfig(name=col_name))
existing_columns.add(col_name)
```
**Knowledge Base Used:** [Workflow compilation and execution](https://app.greptile.com/nvidia-public-github/-/custom-context/knowledge-base/nvidia-nemo/datadesigner/-/docs/workflow-compilation-execution.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly. |
||||||||||||||||||||||||||||||||
| existing_columns.add(col_name) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| def _resolve_and_add_seed_columns(config: DataDesignerConfig, seed_reader: SeedReader | None) -> None: | ||||||||||||||||||||||||||||||||
| """Fetches the seed dataset column names, ensures there are no conflicts | ||||||||||||||||||||||||||||||||
| with other columns, and adds seed column configs to the DataDesignerConfig. | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This applies column declarations from every processor before generation, although processor stages are determined by their runtime implementations. If a POST_BATCH or AFTER_GENERATION processor declares an added column, generation-time templates can reference it successfully during validation even though it will not exist until after generation, causing a runtime failure. Likewise, columns declared as removed by a later-stage processor are hidden from validation before that processor actually runs. Restrict these schema changes to PRE_BATCH processors or make the stage part of the configuration contract.
Knowledge Base Used:
Prompt To Fix With AI