flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] yanghua commented on a change in pull request #6448: [FLINK-9990] [table] Add regexp_extract supported in TableAPI and SQL
Date Tue, 09 Oct 2018 12:33:34 GMT
yanghua 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_r223679909
 
 

 ##########
 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:
   yes, will fix it, hold on.y

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message