xccui commented on a change in pull request #6448: [FLINK-9990] [table] Add 
regexp_extract supported in TableAPI and SQL
URL: https://github.com/apache/flink/pull/6448#discussion_r223678697
 
 

 ##########
 File path: 
flink-libraries/flink-table/src/main/scala/org/apache/flink/table/runtime/functions/ScalarFunctions.scala
 ##########
 @@ -219,6 +220,31 @@ object ScalarFunctions {
     str.replaceAll(regex, Matcher.quoteReplacement(replacement))
   }
 
+  /**
+    * Returns a string extracted with a specified regular expression and a 
regex match group index.
+    */
+  def regexp_extract(str: String, regex: String, extractIndex: Integer): 
String = {
+    if (str == null || regex == null) {
+      return null
+    }
+
+    val m = Pattern.compile(regex).matcher(str)
+    if (m.find) {
+      val mr = m.toMatchResult
+      return mr.group(extractIndex)
+    }
+
+    ""
 
 Review comment:
   I think when no matching found, the method should return null instead of an 
empty string, right?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to