raminqaf commented on code in PR #28189:
URL: https://github.com/apache/flink/pull/28189#discussion_r3258253135
##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/functions/SqlFunctionUtils.java:
##########
@@ -422,21 +422,20 @@ public static String splitIndex(String str, int
character, int index) {
/**
* Returns a string resulting from replacing all substrings that match the
regular expression
- * with replacement.
+ * with replacement. Literal regexes are validated at planning time by the
input type strategy.
*/
public static String regexpReplace(String str, String regex, String
replacement) {
if (str == null || regex == null || replacement == null) {
return null;
}
try {
- return str.replaceAll(regex,
Matcher.quoteReplacement(replacement));
- } catch (Exception e) {
- LOG.error(
- String.format(
- "Exception in regexpReplace('%s', '%s', '%s')",
- str, regex, replacement),
- e);
- // return null if exception in regex replace
+ return REGEXP_PATTERN_CACHE
Review Comment:
Before `String.replaceAll` was calling Pattern.compile(regex) internally on
every invocation. No cache.
The new code uses the ThreadLocalCache, compiled once per regex value per
thread. This is a slight performance boost !
--
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]