Repository navigation
refactor(notebook-migration): select prompts and operator type by source language - #8910
Conversation
|
/request-review @mengw15 |
Automated Reviewer SuggestionsBased on the
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8910 +/- ##
============================================
- Coverage 92.33% 92.33% -0.01%
Complexity 5045 5045
============================================
Files 1261 1261
Lines 54120 54126 +6
Branches 6768 6769 +1
============================================
+ Hits 49974 49979 +5
Misses 2486 2486
- Partials 1660 1661 +1
*This pull request uses carry forward flags. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟡 Changes recommended
Shared notebook metadata introduces mutable state across conversions.
1 open finding
What changed in this PR
Centralizes notebook-migration language settings to prepare for R support while retaining Python behavior.
Changes:
- Adds language-specific prompt, operator, and notebook metadata configuration.
- Parameterizes notebook/script conversion helpers.
- Adds Python behavior regression tests.
| File | Description |
|---|---|
migration-llm.ts |
Introduces and consumes Python migration configuration. |
migration-llm.spec.ts |
Verifies unchanged Python prompts and operator type. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
4 open findings
contentsFor()always inspectscallModelSpy.mock.calls[0]` (the first model invocation). Since… · New contentsFor()always inspectscallModelSpy.mock.calls[0]` (the first model invocation). Since… · New contentsFor()always inspectscallModelSpy.mock.calls[0]` (the first model invocation). Since… · New structuredClone` is not available in all runtime environments/browsers without a polyfill; if the… · New
1 resolved since last review
🧠 Review effort: Lite
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
2 open issues
4 resolved since last review
contentsFor()always inspectscallModelSpy.mock.calls[0]` (the first model invocation). Since… contentsFor()always inspectscallModelSpy.mock.calls[0]` (the first model invocation). Since… contentsFor()always inspectscallModelSpy.mock.calls[0]` (the first model invocation). Since… structuredClone` is not available in all runtime environments/browsers without a polyfill; if the…
Review effort: Lite
…r sources (apache#8911) ### What changes were proposed in this PR? This is the second of the PRs adding R support to the migration tool (apache#8009), building on the prompt sets from apache#8910. It adds the R side of the conversion. Nothing is user visible yet: the import modal options arrive in apache#8912 and apache#8963, and the new flag defaults to off. **Flag.** `gui.workflow-workspace.r-notebook-migration-enabled`, default false, overridable with `GUI_WORKFLOW_WORKSPACE_R_NOTEBOOK_MIGRATION_ENABLED` and exposed to the frontend as `rNotebookMigrationEnabled`. R UDFs only run where the computing unit has the texera-rudf plugin installed (apache#4155), and no Texera image ships it, so R stays off unless a deployment opts in. It sits under the existing migration flag rather than replacing it. **R prompts.** A new `migration-prompts-r.ts` holds an R version of each prompt, notebook and script, with the same JSON reply contract so parsing does not change. The design follows a spike against texera-rudf that ran chained R UDFs in a real workflow: * Every UDF uses the Table API: one `function(table, port)` that takes and returns a data.frame. `RUDF` needs `useTupleAPI` set explicitly, and teaching one API keeps generated code and the flag consistent. * Python passes objects between UDFs pickled in `binary` columns. R has no pickle, so a UDF whose output another UDF reads returns one row of `I(list(serialize(x, NULL)))` columns, and the reader calls `unserialize(table$x[[1]])`. The spike passed data.frames and fitted `lm` models this way between real workers. * A UDF no other UDF reads returns character columns. Texera's schema check rejects a number in a column `buildWorkflow` declares as `string`, and does not cast it. * Plots are converted with `ggplotly()` into a page that loads Plotly from a CDN, returned as `html-content`. `htmlwidgets::saveWidget` is ruled out because it needs pandoc. * Each UDF reads from at most one other UDF. Results a later step needs are carried along one chain instead of merged from branches, which avoids R UDFs having to union tables. The worked examples are the diabetes pipeline in R. Their line numbers, mapping ranges and JSON escaping were generated rather than typed, and all six example UDFs were run through texera-rudf on `diabetes.csv`, chained the way `buildWorkflow` wires them. Unlike the Python examples, they are valid JSON. **Wiring.** `MigrationLanguage` widens to `"python" | "r"`. The R prompt set builds `RUDF` operators with `useTupleAPI: false` through a new `properties` overlay (empty for Python, so Python operators are unchanged) and derives notebooks with the `ir` kernelspec. A `promptsFor` guard refuses an R conversion while the R flag is off, before any model call. `NotebookMigrationService` passes the language through. ### Any related issues, documentation, discussions? Part of apache#8009 Parent-issue apache#4301 The plan is in apache#8866. The import modal options follow in apache#8912 (R notebooks) and apache#8963 (R files), which are stacked on this PR. ### How was this PR tested? * `migration-llm.spec.ts`, six new tests: the exact R prelude and prompts for notebooks and scripts, the full `RUDF` property set with binary and string outputs, the `ir` kernelspec on a derived notebook, the R flag blocking R without a model call, and Python still converting with the R flag off. The Python prompt tests from apache#8910 pass unchanged. * `migration-prompts-r.spec.ts`, new, ten tests guarding the worked examples: both example blocks parse as JSON, edges only reference defined UDFs, every UDF is a numbered Table API function, only UDFs another UDF reads call `serialize`, no UDF has two inputs, and the mapping cells and line ranges point at real, non blank lines. * `notebook-migration.service.spec.ts`, two new tests that the language reaches both conversions. * `GuiConfigSpec` checks the flag defaults to false. Coverage of `migration-llm.ts` and `notebook-migration.service.ts` stays at 100% of lines. The full frontend suite passes. End to end with a live model, through the modal from apache#8912 and apache#8963: an R script and an R notebook each converted to a workflow of Table API `RUDF` operators. Run on the source dataset, the script's workflow reported the same model accuracies as running the original script in `Rscript`, and its plot rendered through an HTML Visualizer. ### Was this PR authored or co-authored using generative AI tooling? Generated-by: Claude Code (Claude Opus 5.5) --------- Co-authored-by: Meng Wang <[email protected]>



What changes were proposed in this PR?
This is the first of three PRs adding R support to the migration tool (#8009). It is a pure refactor with no behavior change: Python conversions send the same prompts and build the same operators as before.
The migration tool hardcodes Python in three places that R needs to vary: the documentation and prompts sent to the model, the operator type built from each generated UDF (
PythonUDFV2), and the kernelspec of the notebook derived for a script. This PR gathers those into oneMigrationPromptSetper source language, held in aPROMPT_SETStable that only has a Python entry for now.convertNotebookToWorkflowandconvertScriptToWorkflowtake alanguageargument, defaulting to"python", and read everything from the set.buildWorkflow,requestConversionandfinishConversionreceive the operator type and notebook metadata as arguments instead of hardcoding them.MigrationLanguageis"python"only in this PR. The next PR widens it to"python" | "r"and adds the R set.Any related issues, documentation, discussions?
Part of #8009
Parent-issue #4301
The plan for R support is in #8866. The follow up PRs add the R prompts and the R option in the import modal. They are stacked on this one.
How was this PR tested?
Three new tests in
migration-llm.spec.tspin the Python output so later changes cannot alter it silently:PythonUDFV2.The existing notebook, script and folder tests pass unchanged. Coverage of
migration-llm.tsis 100% of lines; the one uncovered branch is the@Injectable()decorator, as before this change. The full frontend suite passes.Was this PR authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Claude Opus 5.5)