eugenegujing opened a new pull request, #9215:
URL: https://github.com/apache/texera/pull/9215

   ### What changes were proposed in this PR?
   
   **Root cause.** A `PythonOperatorDescriptor` whose code generation throws 
replaces its whole code with the line `#EXCEPTION DURING CODE GENERATION: 
<message>` (`PythonOperatorDescriptor.scala:29`), and `WorkflowCompiler` turns 
that marker back into a per-operator COMPILATION_ERROR. The compiler's regex 
was unanchored, so it matched the marker text anywhere in the code of every 
Python-based operator, including Python and R UDFs whose code is the user's own 
script. A UDF that mentioned the marker text in a comment or a string was 
rejected, the physical plan was dropped, and the reported error was the rest of 
the user's comment line.
   
   ```text
   Before:  "...\n# NOTE: #EXCEPTION DURING CODE GENERATION: only a 
comment\n..." -> COMPILATION_ERROR "Operator is not configured properly: only a 
comment", no physical plan
   After:   same UDF                                                          
-> compiles, physical plan kept
            "#EXCEPTION DURING CODE GENERATION: <msg>" (whole code)           
-> COMPILATION_ERROR as before
   ```
   
   **Before (local main 92e86d420, workflow Text Input → Python UDF with the 
NOTE comment on line 3).**
   
   <img width="1456" height="829" alt="01-udf-with-marker-comment-static-error" 
src="https://github.com/user-attachments/assets/50f2e482-ca4b-42ca-905b-f8d5edfbd766";
 />
   
   <img width="1456" height="829" 
alt="02-udf-code-editor-comment-and-fabricated-error" 
src="https://github.com/user-attachments/assets/a3e614e6-957f-4fb6-848d-84892d8ed6b7";
 />
   
   <img width="1456" height="829" alt="03-same-udf-without-comment-run-enabled" 
src="https://github.com/user-attachments/assets/6a3813c2-149d-41b7-9a0e-8505ac95f321";
 />
   
   **After (this branch, the same workflow with the comment still on line 3).**
   
   <img width="1512" height="720" 
alt="after-01-udf-with-marker-comment-run-enabled-no-static-error" 
src="https://github.com/user-attachments/assets/9512f3b7-f652-4dcb-a07b-45d9282f8850";
 />
   
   <img width="1512" height="720" 
alt="after-02-udf-code-editor-comment-run-enabled" 
src="https://github.com/user-attachments/assets/31023021-38e5-4a24-aa7a-da56a9cb757e";
 />
   
   The third screenshot is also what the UDF with the comment looks like after 
this change: no Static Error and an enabled Run button.
   
   **Changes.**
   
   - `WorkflowCompiler.scala`: the regex becomes `(?s)^#EXCEPTION DURING CODE 
GENERATION:\s*(.*)`. `^` restricts the match to the start of the code, which is 
the only place the marker is ever written; `(?s)` lets the captured message 
include line breaks, so a multi-line generation failure is reported in full 
instead of its first line.
   - `PythonOperatorDescriptor.scala`: an exception whose message is `null` or 
empty is rendered as `ex.toString` (its class name, plus `: ` for the empty 
case) instead of the literal `null` or nothing.
   
   **Scope.** The in-band marker design itself is left as is; moving the 
failure out of the code string would touch `PhysicalOp` and every consumer and 
is out of scope here.
   
   ### Any related issues, documentation, discussions?
   
   Closes #9213
   
   ### How was this PR tested?
   
   Added to `WorkflowCompilerSpec` (Python code-generation error path section):
   
   - a `PythonUDFOpDescV2` whose script contains the marker in a comment 
compiles with no error and keeps its physical plan (the test also asserts the 
marker text did reach the check);
   - a test-only `PythonOperatorDescriptor` whose generated code mentions the 
marker mid-code compiles with no error;
   - a generation failure with a `null` message is reported as `Operator is not 
configured properly: java.lang.RuntimeException`;
   - a multi-line failure message is reported in full, with both `\n` and 
`\r\n` line endings;
   - a Python UDF whose code starts with the marker line is still reported as a 
code-generation error with that message (the intended boundary of the anchor);
   - an R UDF (`RUDFOpDesc`) whose code mentions the marker in a comment 
compiles with no error and keeps its physical plan.
   
   Added to `PythonOperatorDescriptorSpec`: the embedded marker for an 
exception without a message and for one with an empty message (`#EXCEPTION 
DURING CODE GENERATION: java.lang.RuntimeException: `). The existing tests for 
real generation failures (unconfigured Sort, padded message) are unchanged and 
still pass.
   
   ```
   sbt "WorkflowOperator/testOnly 
org.apache.texera.amber.operator.PythonOperatorDescriptorSpec" 
"WorkflowCompiler/testOnly 
org.apache.texera.common.compiler.WorkflowCompilerSpec"
   ```
   
   - Red (first batch of tests against unmodified source): 
PythonOperatorDescriptorSpec 3 passed, 1 failed; WorkflowCompilerSpec 34 
passed, 4 failed, e.g. the UDF case produced `Operator is not configured 
properly: this is only a comment` with `physicalPlan = None`.
   - Green (with this change): PythonOperatorDescriptorSpec 5 passed, 
WorkflowCompilerSpec 41 passed, 0 failed (2 and 7 new tests). The empty-message 
test was red first (4 passed, 1 failed) before the `filter(_.nonEmpty)` 
fallback was added.
   - Mutation check (full suites): reverting both source lines fails 8 of the 9 
new tests (PythonOperatorDescriptorSpec 3 passed / 2 failed, 
WorkflowCompilerSpec 35 passed / 6 failed); the UDF-starts-with-the-marker test 
passes either way by design. Removing only the `filter(_.nonEmpty)` fails 
exactly the empty-message test (4 passed / 1 failed, compiler spec 41 / 0). 
Restored afterwards.
   - `scalafmtCheck`, `Test/scalafmtCheck`, `scalafix --check` and 
`Test/scalafix --check` on `WorkflowCompiler` and `WorkflowOperator`: all pass.
   
   ### Was this PR authored or co-authored using generative AI tooling?
   
   Yes. Generated-by: Claude Code (claude-fable-5-1). Co-authored with Claude; 
the author reviewed the change before submission.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to