raminqaf opened a new pull request, #28189:
URL: https://github.com/apache/flink/pull/28189

   ## What is the purpose of the change
   `REGEXP_REPLACE` does not validate literal regex patterns at planning time. 
When the regex is a string literal that fails `Pattern.compile`, every record 
produces an `ERROR`-level log line and a wasted compile attempt on the hot path 
(`String.replaceAll` recompiles per call). This PR surfaces the failure as a 
`ValidationException` during type inference and removes the per-record log spam.
    
   This is the second sub-task of the FLINK-39648 umbrella, following the same 
pattern established for `REGEXP_EXTRACT` (FLINK-39649). The shared 
literal-pattern validation logic is extracted into `RegexpUtils` so the 
remaining sub-tasks (`REGEXP`, etc.) can reuse it.
   
   ## Brief change log
   - Add `RegexpUtils.validateLiteralPattern(callContext, regexArgPos, 
throwOnFailure)` as a shared helper.
   - Refactor `RegexpExtractInputTypeStrategy` to delegate to `RegexpUtils`.
   - Add `RegexpReplaceInputTypeStrategy` that validates 3 STRING args and the 
literal regex via `RegexpUtils`.
   - Migrate `BuiltInFunctionDefinitions.REGEXP_REPLACE` to 
`name("REGEXP_REPLACE")` + `runtimeProvided()`. Drop `sqlName`. Use the new 
strategy.
   - Remove the legacy `FlinkSqlOperatorTable.REGEXP_REPLACE` entry, the 
`DirectConvertRule` mapping, and the `case REGEXP_REPLACE` arm in 
`StringCallGen`.
   - Add `case REGEXP_REPLACE => StringCallGen.generateRegexpReplace(...)` in 
`ExprCodeGenerator`'s `BridgingSqlFunction` block.
   - Rewrite `SqlFunctionUtils.regexpReplace` to use 
`REGEXP_PATTERN_CACHE.get(regex).matcher(str).replaceAll(...)`. Silent `null` 
return on `PatternSyntaxException`. No `LOG.error` on the hot path.
   
   ## Verifying this change
   
   This change added tests and can be verified as follows:
   - New `RegexpReplaceInputTypeStrategyTest` covers four branches: non-literal 
regex defers, valid literal compiles, null literal is deferred, invalid literal 
fails at plan time.
   - New `regexpReplaceTestCases()` in `RegexpFunctionsITCase` covers runtime 
behavior end-to-end: literal valid replace, column-ref invalid regex returns 
null, function-call regex (CONCAT) valid and invalid, ValidationException for 
invalid literal via Table API and SQL.
   - Existing `RegexpFunctionsITCase` and `ScalarFunctionsTest` regress all 
other regex functions.
   
   ## Does this pull request potentially affect one of the following parts:
   - Dependencies (does it add or upgrade a dependency): no
   - The public API, i.e., is any changed class annotated with 
`@Public(Evolving)`: no
   - The serializers: no
   - The runtime per-record code paths (performance sensitive): yes (removes 
per-record `Pattern.compile` and `LOG.error` in `regexpReplace`; uses cached 
pattern instead)
   - Anything that affects deployment or recovery: JobManager (and its 
components), Checkpointing, Kubernetes/Yarn, ZooKeeper: no
   - The S3 file system connector: no
   
   ## Documentation
   - Does this pull request introduce a new feature? no
   - If yes, how is the feature documented? not applicable
   
   ---
   ##### Was generative AI tooling used to co-author this PR?
   
   - [x] Yes (please specify the tool below)
   
   Generated-by: Opus 4.7


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