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


##########
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) {
+            // non-literal invalid regex returns null.

Review Comment:
   This is a bit usual behavior, usually we should throw here, but I guess we 
don't want to break existing pipelines. It is a niche case anyways.



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