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

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_r310098359
 
 

 ##########
 File path: sdks/python/apache_beam/transforms/util_test.py
 ##########
 @@ -618,6 +619,290 @@ def test_window_in_value(self):
       assert_that(reified_pc, equal_to(expected), reify_windows=True)
 
 
+class RegexTest(unittest.TestCase):
+
+  def test_find(self):
+    with TestPipeline() as p:
+      result = (p | beam.Create(["aj", "xj", "yj", "zj"])
+                | util.Regex.find("[xyz]"))
+      assert_that(result, equal_to(["x", "y", "z"]))
+
+  def test_find_pattern(self):
+    with TestPipeline() as p:
+      rc = re.compile("[xyz]")
+      result = (p | beam.Create(["aj", "xj", "yj", "zj"]) | 
util.Regex.find(rc))
+      assert_that(result, equal_to(["x", "y", "z"]))
+
+  def test_find_group(self):
+    with TestPipeline() as p:
+      result = (p | beam.Create(["aj", "xj", "yj", "zj"])
+                | util.Regex.find("([xyz])", group=1))
+      assert_that(result, equal_to(["x", "y", "z"]))
+
+  def test_find_empty(self):
+    with TestPipeline() as p:
+      result = (p | beam.Create(["a", "b", "c", "d"])
+                | util.Regex.find("[xyz]"))
+      assert_that(result, equal_to([]))
+
+  def test_find_group_name(self):
+    with TestPipeline() as p:
+      result = (p | beam.Create(["aj", "xj", "yj", "zj"])
+                | util.Regex.find("(?P<namedgroup>[xyz])", group="namedgroup"))
+      assert_that(result, equal_to(["x", "y", "z"]))
+
+  def test_find_group_name_pattern(self):
+    with TestPipeline() as p:
+      rc = re.compile("(?P<namedgroup>[xyz])")
+      result = (p | beam.Create(["aj", "xj", "yj", "zj"]) | util.Regex.find(
+          rc, group="namedgroup"))
+      assert_that(result, equal_to(["x", "y", "z"]))
+
+  def test_find_all_groups(self):
+    data = ["abb ax abbb", "abc abcabc"]
+    with TestPipeline() as p:
+      result = (p | beam.Create(data)
+                | util.Regex.find_all("a(b*)"))
+      expected_retult = [['abb', 'a', 'abbb'], ['ab', 'ab', 'ab']]
 
 Review comment:
   spelling
 
----------------------------------------------------------------
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:
us...@infra.apache.org


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

    Worklog Id:     (was: 287880)
    Time Spent: 11.5h  (was: 11h 20m)

> 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: 11.5h
>  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