Skip to content

refactor(notebook-migration): select prompts and operator type by source language - #8910

Merged
mengw15 merged 4 commits into
apache:mainfrom
zyratlo:migration-tool-r-prompt-sets
Oct 29, 2026
Merged

mengw15 merged 4 commits into
apache:mainfrom
zyratlo:migration-tool-r-prompt-sets

Conversation

@zyratlo

@zyratlo zyratlo commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

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 one MigrationPromptSet per source language, held in a PROMPT_SETS table that only has a Python entry for now.

  • convertNotebookToWorkflow and convertScriptToWorkflow take a language argument, defaulting to "python", and read everything from the set.
  • buildWorkflow, requestConversion and finishConversion receive the operator type and notebook metadata as arguments instead of hardcoding them.
  • The three Python documentation arrays move from private statics on the class to module level constants, unchanged, so the table can reference them.
  • The folder path uses the Python set explicitly. R folders come in a later PR.

MigrationLanguage is "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.ts pin the Python output so later changes cannot alter it silently:

  • The notebook path sends exactly the existing system prelude, workflow prompt and mapping prompt.
  • The script path does the same with the script prelude and prompts.
  • Generated operators are built as PythonUDFV2.

The existing notebook, script and folder tests pass unchanged. Coverage of migration-llm.ts is 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)

@zyratlo

zyratlo commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

/request-review @mengw15

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Automated Reviewer Suggestions

Based on the git blame history of the changed files, we recommend the following reviewers:

  • No candidates found from git blame history.

@codecov-commenter

codecov-commenter commented Oct 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.33%. Comparing base (22b82a2) to head (55f56c8).

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     
Flag Coverage Δ *Carryforward flag
access-control-service 77.38% <ø> (ø) Carriedforward from 3726dd7
agent-service 99.16% <ø> (ø) Carriedforward from 3726dd7
amber 87.31% <ø> (ø) Carriedforward from 3726dd7
computing-unit-managing-service 60.48% <ø> (ø) Carriedforward from 3726dd7
config-service 87.37% <ø> (ø) Carriedforward from 3726dd7
file-service 82.00% <ø> (ø) Carriedforward from 3726dd7
frontend 96.55% <100.00%> (-0.01%) ⬇️
notebook-migration-service 83.73% <ø> (ø) Carriedforward from 3726dd7
pyamber 98.57% <ø> (ø) Carriedforward from 3726dd7
workflow-compiling-service 72.43% <ø> (ø) Carriedforward from 3726dd7

*This pull request uses carry forward flags. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI 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.

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

@mengw15
mengw15 requested a balanced review from Copilot October 15, 2026 21:03

Copilot AI 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.

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
1 resolved since last review

🧠 Review effort: Lite

@mengw15
mengw15 requested a balanced review from Copilot October 23, 2026 21:41

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

LGTM

Copilot AI 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.

@mengw15
mengw15 added this pull request to the merge queue Oct 29, 2026
Merged via the queue into apache:main with commit 8b89d0c Oct 29, 2026
26 checks passed
renovate-bot pushed a commit to renovate-bot/apache-_-texera that referenced this pull request Nov 9, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

frontend Changes related to the frontend GUI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants