[ 
https://issues.apache.org/jira/browse/FLINK-9990?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16643258#comment-16643258
 ] 

ASF GitHub Bot commented on FLINK-9990:
---------------------------------------

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]


> Add regexp_extract supported in TableAPI and SQL
> ------------------------------------------------
>
>                 Key: FLINK-9990
>                 URL: https://issues.apache.org/jira/browse/FLINK-9990
>             Project: Flink
>          Issue Type: Sub-task
>          Components: Table API & SQL
>            Reporter: vinoyang
>            Assignee: vinoyang
>            Priority: Minor
>              Labels: pull-request-available
>
> regex_extract is a very useful function, it returns a string based on a regex 
> pattern and a index.
> For example : 
> {code:java}
> regexp_extract('foothebar', 'foo(.*?)(bar)', 2) // returns 'bar.'
> {code}
> It is provided as a UDF in Hive, more details please see[1].
> [1]: https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to