leocook opened a new pull request, #18231:
URL: https://github.com/apache/dolphinscheduler/pull/18231

   ## Was this PR generated or assisted by AI?
   
   YES, Opus 4.7
   
   ## Purpose of the pull request
   
   close #18074 
   
   ## Brief change log
   
   When an upstream SQL task outputs parameter `p1` and the downstream task 
references it via a different parameter name `p2` (with value `${p1}`), the 
workflow fails with:
   
   ```
   java.lang.IllegalArgumentException: No group with name {p1}
       at java.util.regex.Matcher.appendReplacement(Matcher.java:849)
       at 
org.apache.dolphinscheduler.plugin.task.sql.SqlTask.replaceOriginalValue(SqlTask.java:496)
   ```
   
   Two root causes:
   
   1. **VarPool not injected**: 
`CuringParamsServiceImpl.paramParsingPreparation()` step 6 only overrides 
parameters with the same name. Since the downstream task only has `p2` and not 
`p1`, the upstream VarPool value (`p1=111`) gets dropped, causing `${p1}` to 
remain unresolved.
   
   2. **Unsafe regex replacement**: `SqlTask.replaceOriginalValue()` uses 
`Matcher.replaceFirst(paramValue)` directly, which treats `$` as a regex group 
reference. When the unresolved placeholder `${p1}` contains `$`, it causes the 
regex engine to crash.
   
   **Changes:**
   
   - `CuringParamsServiceImpl`: Inject VarPool parameters that don't exist in 
`prepareParamsMap` for downstream placeholder resolution
   - `SqlTask`: Use `Matcher.quoteReplacement()` to safely handle `$` in 
parameter values, and add null safety check
   
   ## Verify this pull request
   
   This pull request is covered by new unit tests:
   
   - 
`CuringParamsServiceImplTest.testParamParsingPreparation_varPoolInjectionWhenParamNameNotInLocalParams`
 — verifies upstream VarPool parameter `p1` is injected and downstream 
`p2=${p1}` is resolved to `111`
   - `SqlTaskTest.testReplaceOriginalValue_withSpecialCharacters` — verifies 
`$`, `\` characters in values are safely replaced
   - `SqlTaskTest.testReplaceOriginalValue_paramNotFound_keepsOriginalText` — 
verifies original text is preserved when parameter is not found
   - `SqlTaskTest.testReplaceOriginalValue_paramValueNull_keepsOriginalText` — 
verifies original text is preserved when parameter value is null
   
   ## Screenshots
   
   Before fix:
   <img width="1132" height="930" alt="image" 
src="https://github.com/user-attachments/assets/ab41c3c2-60ee-4d3a-b727-fb155f945322";
 />
   <img width="1784" height="574" alt="image" 
src="https://github.com/user-attachments/assets/a0d1b695-ad8f-4c33-8b63-01d12ef7b267";
 />
   
   After fix:
   <img width="1882" height="134" alt="image" 
src="https://github.com/user-attachments/assets/d60fbf41-2d0f-4943-9e48-106d1c966e7d";
 />
   <img width="1974" height="166" alt="image" 
src="https://github.com/user-attachments/assets/13cdc119-82f4-4b87-ac28-f741d6dbf11f";
 />
   
   
   ## Pull Request Notice
   
   [Pull Request 
Notice](https://github.com/apache/dolphinscheduler/blob/dev/docs/docs/en/contribute/join/pull-request.md)
   
   If your pull request contains incompatible change, you should also add it to 
`docs/docs/en/guide/upgrade/incompatible.md`
   


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