[ 
https://issues.apache.org/jira/browse/BEAM-7018?focusedWorklogId=287874&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-287874
 ]

ASF GitHub Bot logged work on BEAM-7018:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 02/Aug/19 12:01
            Start Date: 02/Aug/19 12:01
    Worklog Time Spent: 10m 
      Work Description: robertwb commented on pull request #8859: [BEAM-7018] 
Added Regex transform for PythonSDK
URL: https://github.com/apache/beam/pull/8859#discussion_r310095335
 
 

 ##########
 File path: sdks/python/apache_beam/transforms/util.py
 ##########
 @@ -865,3 +868,220 @@ def add_window_info(element, 
timestamp=DoFn.TimestampParam,
 
     def expand(self, pcoll):
       return pcoll | ParDo(self.add_window_info)
+
+
+class Regex(object):
+  """
+  PTransform  to use Regular Expression to process the elements in a
+  PCollection.
+  """
+
+  ALL = "__regex_all_groups"
+
+  @staticmethod
+  def _regex_compile(regex):
+    """Return re.compile if the regex has a string value"""
+    if isinstance(regex, str):
+      regex = re.compile(regex)
+    return regex
+
+  @staticmethod
+  @typehints.with_input_types(str)
+  @typehints.with_output_types(str)
+  @ptransform_fn
+  def matches(pcoll, regex, group=0):
+    """
+    Returns the matches (group 0 by default) if zero or more characters at the
+    beginning of string match the regular expression. To match the entire
+    string, add "$" sign at the end of regex expression.
+
+    Group can be integer value or a string value.
+
+    Args:
+      regex: the regular expression string or (re.compile) pattern.
+      group: (optional) name/number of the group, it can be integer or a string
+        value.
 
 Review comment:
   Defaults to 0, meaning the entire matched string will be returned. 
 
----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 287874)
    Time Spent: 10h 50m  (was: 10h 40m)

> Regex transform for Python SDK
> ------------------------------
>
>                 Key: BEAM-7018
>                 URL: https://issues.apache.org/jira/browse/BEAM-7018
>             Project: Beam
>          Issue Type: New Feature
>          Components: sdk-py-core
>            Reporter: Rose Nguyen
>            Assignee: Shehzaad Nakhoda
>            Priority: Minor
>          Time Spent: 10h 50m
>  Remaining Estimate: 0h
>
> PTransorms to use Regular Expressions to process elements in a PCollection
> It should offer the same API as its Java counterpart: 
> [https://github.com/apache/beam/blob/11a977b8b26eff2274d706541127c19dc93131a2/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/Regex.java]



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)

Reply via email to