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

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

                Author: ASF GitHub Bot
            Created on: 05/Aug/19 12:37
            Start Date: 05/Aug/19 12:37
    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_r310582270
 
 

 ##########
 File path: sdks/python/apache_beam/transforms/util_test.py
 ##########
 @@ -648,68 +648,70 @@ def test_find_empty(self):
   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"))
+                | util.Regex.find("(?P<namedgroup>[xyz])j", 
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])")
+      rc = re.compile("(?P<namedgroup>[xyz])j")
       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"]
+    data = ["abb ax abbb", "abc qwerty abcabcd xyz"]
     with TestPipeline() as p:
-      result = (p | beam.Create(data)
-                | util.Regex.find_all("a(b*)"))
-      expected_retult = [['abb', 'a', 'abbb'], ['ab', 'ab', 'ab']]
-      assert_that(result, equal_to(expected_retult))
+      pcol = (p | beam.Create(data))
+      test1 = (pcol | 'test 1' >> util.Regex.find_all("a(b*)"))
 
-    with TestPipeline() as p:
       # Find all with group 1
-      result = (p | beam.Create(data)
-                | util.Regex.find_all("a(b*)", 1))
-      expected_retult = [['b', 'b', 'b'], ['bb', '', 'bbb']]
-      assert_that(result, equal_to(expected_retult))
+      test2 = (pcol | 'test 2' >> util.Regex.find_all("a(b*)", 1))
 
-    with TestPipeline() as p:
       # Find all with group 1 and remove empty items
-      result = (p | beam.Create(data)
-                | util.Regex.find_all("a(b*)", 1, outputEmpty=False))
-      expected_retult = [['b', 'b', 'b'], ['bb', 'bbb']]
-      assert_that(result, equal_to(expected_retult))
+      test3 = (pcol | 'test 3' >> util.Regex.find_all("a(b*)", 1,
+                                                      outputEmpty=False))
 
-    with TestPipeline() as p:
       # Find all with named group
-      result = (p | beam.Create(data)
-                | util.Regex.find_all("a(?P<namedgroup>b*)", 'namedgroup'))
-      expected_retult = [['b', 'b', 'b'], ['bb', '', 'bbb']]
-      assert_that(result, equal_to(expected_retult))
+      test4 = (pcol | 'test 4' >> util.Regex.find_all("a(?P<namedgroup>b*)",
+                                                      'namedgroup'))
 
-    with TestPipeline() as p:
       # Find all with named group with override Regex.ALL flag which return
       # all the groups in tuple format
-      result = (p | beam.Create(data)
-                | util.Regex.find_all("a(?P<namedgroup>b*)", util.Regex.ALL))
-      expected_retult = [[('ab', 'b'), ('ab', 'b'), ('ab', 'b')],
-                         [('abb', 'bb'), ('a', ''), ('abbb', 'bbb')]]
-      assert_that(result, equal_to(expected_retult))
+      test5 = (pcol | 'test 5' >> util.Regex.find_all("a(?P<namedgroup>b*)",
+                                                      util.Regex.ALL))
 
-    with TestPipeline() as p:
       # Find all with Regex.ALL flag and removes the empty groups items
-      result = (p | beam.Create(data)
-                | util.Regex.find_all("a(b*)", util.Regex.ALL,
-                                      outputEmpty=False))
-      expected_retult = [[('ab', 'b'), ('ab', 'b'), ('ab', 'b')],
-                         [('abb', 'bb'), ('abbb', 'bbb')]]
-      assert_that(result, equal_to(expected_retult))
+      test6 = (pcol | 'test 6' >> util.Regex.find_all("a(b*)", util.Regex.ALL,
+                                                      outputEmpty=False))
+
+      test1_expected = [['abb', 'a', 'abbb'], ['ab', 'ab', 'ab']]
+      test2_expected = [['b', 'b', 'b'], ['bb', '', 'bbb']]
+      test3_expected = [['b', 'b', 'b'], ['bb', 'bbb']]
+      test4_expected = [['b', 'b', 'b'], ['bb', '', 'bbb']]
+      test5_expected = [[('ab', 'b'), ('ab', 'b'), ('ab', 'b')],
+                        [('abb', 'bb'), ('a', ''), ('abbb', 'bbb')]]
+      test6_expected = [[('ab', 'b'), ('ab', 'b'), ('ab', 'b')],
+                        [('abb', 'bb'), ('abbb', 'bbb')]]
+
+      assert_that(test1, equal_to(test1_expected), label='assert test 1')
 
 Review comment:
   I would still put the test expectations up next to the defines, and label 
them in a meaningful way. Probably getting rid of the intermediates would make 
this easier to read, e.g.
   
   ```
   assert_that(
       pcol | 'group 1' >> util.Regex.find_all("a(b*)", group=1),
       equal_to([['b', 'b', 'b'], ['bb', '', 'bbb']]),
       label='CheckGroup1')
   
   assert_that(
       pcol | 'group 1 non empty' >> util.Regex.find_all("a(b*)", group=1, 
outputEmpty=False),
       equal_to([['b', 'b', 'b'], ['bb','bbb']]),
       label='CheckGroup1NoEmpty')
   
   ...
   ```
   
 
----------------------------------------------------------------
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: 288915)
    Time Spent: 11h 50m  (was: 11h 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: 11h 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