jacktengg opened a new pull request, #71360:
URL: https://github.com/apache/doris/pull/71360

   Backport of #71309 to `branch-4.2`.
   
   Original merged commit: `89529eac8c31ef6cbe361148f6c10756ee6a99dd`.
   
   ### Backport adjustments
   
   - Port strict replacement validation to both separate 4.2 implementations 
(`RegexpReplaceImpl` and `RegexpReplaceOneImpl`). Keep validation local to each 
block for constant pattern/replacement pairs.
   - Preserve NULL maps in the shared replacement-function wrapper before 
validation. The 4.2 generic NULL wrapper otherwise evaluates masked payloads 
and would incorrectly reject NULL rows containing malformed rewrites.
   - Retain the upstream regression suite and generated expected results 
unchanged. Add a BE unit test for the release-specific NULL adaptation, 
including three/four arguments and a NULL first row followed by an invalid 
constant rewrite.
   
   ### Backport validation
   
   - Scoped repository clang-format 16.0.6/check-format and `git diff --cached 
--check`: passed.
   - Both changed C++ translation units were parsed using the branch-4.2 ASAN 
UT compilation database and clang-tidy 20 (`clang-analyzer-core.*`). No 
compiler errors or diagnostics on changed lines. Full-file analysis returned 
exit 1 because four existing uninitialized-condition diagnostics in the 
unchanged regexp extraction implementation were promoted by WarningsAsErrors; 
these are outside this backport.
   - Both SQL regression files are byte-identical to the upstream PR, including 
its generated expected output.
   - Started `./run-be-ut.sh --run 
--filter='FunctionConstantArgumentTest.regexp*:FunctionLikeTest.regexp*' -j24`, 
then stopped during the full rebuild on a heavily loaded host. No unit tests 
executed; no passing UT result is claimed.
   - The branch-4.2 cluster regression suite was not run locally. CI validation 
will be requested with `run buildall`.
   - The release branch has no `build-support/run-clang-tidy.sh` or 
`build-support/check-build-hygiene.sh`; the direct clang-tidy check above was 
used as a limited fallback.
   
   Pre-submission status: Partially verified: local BE UT and target-branch SQL 
regression have not run; CI validation pending.
   
   The original description below is retained for context. Its build, unit-test 
and regression results were obtained on master; they are not evidence of a 
branch-4.2 run.
   
   <details>
   <summary>Original PR description (master)</summary>
   
   ### Background
   
   REGEXP_REPLACE and REGEXP_REPLACE_ONE use RE2 to replace all matches or the 
first match. Both accept capture references in the replacement and an explicit 
IGNORE_INVALID_ESCAPE option.
   
   ### What problem does this PR solve?
   
   Issue Number: None
   Related PR: #8307 (introduced global replacement), #13766 (introduced 
first-match replacement)
   PR Type: Bugfix
   
   Problem Summary:
   
   With one match and replacement `X\xY`, default-mode global replacement can 
keep only the prefix while first-match replacement leaves the input unchanged. 
Both silently accept an invalid rewrite. Validate strict rewrites before either 
operation so both report a meaningful argument error; legal backreferences, 
explicit IGNORE_INVALID_ESCAPE and NULL propagation remain unchanged.
   
   ### Details
   
   - **Frequency:** Always for the tested malformed escapes, trailing backslash 
and missing capture group in strict mode; real BE baseline tests returned OK 
for all 48 calls.
   - **Root cause:** RegexpReplaceImpl ignores RE2's replacement failure 
semantics and does not validate rewrite syntax. Replace and GlobalReplace 
handle a failed rewrite differently.
   - **Why existing tests missed it:** FunctionLikeTest covers successful 
replacement/backreferences/NULLs; FunctionConstantArgumentTest covers constant 
options and block changes. Native test_regexp_replace and 
test_regexp_invalid_pattern exercise permissive replacement and pattern 
failures, without asserting rejection of invalid strict rewrites.
   - **Fix:** Reuse CheckRewriteString in the common replacement path after 
NULL skipping and before modifying the source. Skip strict validation for the 
existing permissive option. Constant pattern/replacement pairs validate once 
per block, preserving lazy-join block boundaries.
   - **Other paths and branches:** Three- and four-argument, constant and 
column paths for both functions are covered. Extract/match functions have no 
replacement argument. Cached branch-3.1/4.0/4.1/4.2 have the same omission; 
only master was built and run. External dialect-conversion services were not 
exercised.
   - **Behavior change:** Invalid strict replacement arguments now fail, 
including when the source has no match, instead of silently returning partial 
or unchanged text.
   
   ### Testing
   
   - Local ASAN baseline: 
`FunctionConstantArgumentTest.regexp_replace_invalid_rewrite` fails because all 
48 executions incorrectly return OK.
   - Local ASAN candidate: `./run-be-ut.sh --run 
--filter='FunctionConstantArgumentTest.regexp*:FunctionLikeTest.regexp*' -j48` 
passes all 27 tests.
   - `./build.sh --be --fe -j48 --output <isolated-output>` passes. The first 
attempt found an obsolete generated FE annotation after switching branches; 
moving stale generated annotations and rerunning the standard build resolved it.
   - Generated and independently checked test_regexp_invalid_rewrite.out: legal 
captures yield aXbYc, explicit permissive replacements yield aXxYc, NULL rows 
remain NULL. BE constant folding is tested both enabled and disabled.
   - `./run-regression-test.sh --run -d 
query_p0/sql_functions/string_functions,nereids_syntax_p0 -s 
test_regexp_invalid_rewrite,test_regexp_invalid_pattern,test_regexp_replace` 
passes all 3 suites with no skips.
   - Scoped repository clang-format 16/check-format and clang-tidy pass on both 
changed C++ files. `git diff --check` passes.
   
   ### Release note
   
   REGEXP_REPLACE and REGEXP_REPLACE_ONE now consistently reject invalid 
replacement strings in default mode. IGNORE_INVALID_ESCAPE retains its existing 
permissive behavior.
   
   ### Check List (For Author)
   
   - Behavior changed: Yes (see Details)
   - Does this need documentation: Yes; clarify strict rewrite errors and 
unchanged IGNORE_INVALID_ESCAPE behavior in the corresponding 
apache/doris-website SQL function pages.
   - Pre-submission status: Ready
   
   ### AI Disclosure
   
   - Tool: Codex (GPT-6)
   - Generated: Implementation, unit/regression tests and this description.
   - Human review: Pending author review.
   
   </details>
   


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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to