raminqaf commented on code in PR #28140:
URL: https://github.com/apache/flink/pull/28140#discussion_r3224366354


##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/functions/SqlFunctionUtils.java:
##########
@@ -444,26 +443,23 @@ public static String regexpReplace(String str, String 
regex, String replacement)
 
     /**
      * Returns a string extracted with a specified regular expression and a 
regex match group index.
+     * Literal regexes are validated at planning time by the input type 
strategy.
      */
     public static String regexpExtract(String str, String regex, int 
extractIndex) {
-        if (str == null || regex == null) {
+        if (str == null || regex == null || extractIndex < 0) {
             return null;
         }
-
         try {
-            Matcher m = Pattern.compile(regex).matcher(str);
+            final Matcher m = REGEXP_PATTERN_CACHE.get(regex).matcher(str);
+            if (m.groupCount() < extractIndex) {
+                return null;
+            }
             if (m.find()) {
-                MatchResult mr = m.toMatchResult();
-                return mr.group(extractIndex);
+                return m.group(extractIndex);
             }
-        } catch (Exception e) {
-            LOG.error(
-                    String.format(
-                            "Exception in regexpExtract('%s', '%s', '%d')",
-                            str, regex, extractIndex),
-                    e);
+        } catch (PatternSyntaxException e) {

Review Comment:
   Thanks for the review. This isn't a Guava `LoadingCache`. 
`REGEXP_PATTERN_CACHE` is `org.apache.flink.table.utils.ThreadLocalCache`, an 
internal Flink class whose `get(K)` doesn't declare `ExecutionException`. The 
loader (Pattern.compile) runs inline and can only throw 
`PatternSyntaxException`, which is caught. No change needed.
   



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