anishmehta24 commented on code in PR #40399:
URL: https://github.com/apache/beam/pull/40399#discussion_r4188101135


##########
sdks/python/apache_beam/transforms/util.py:
##########
@@ -2234,8 +2234,8 @@ def find_all(pcoll, regex, group=0, outputEmpty=True):
     def _process(element):
       matches = regex.finditer(element)
       if group == Regex.ALL:
-        yield [(m.group(), m.groups()[0]) for m in matches
-               if outputEmpty or m.groups()[0]]
+        yield [(m.group(), *m.groups()) for m in matches
+               if outputEmpty or any(m.groups() or (m.group(), ))]

Review Comment:
   Applied, thanks. `all` keeps the single-group behaviour.



##########
sdks/python/apache_beam/transforms/util_test.py:
##########
@@ -2678,6 +2678,21 @@ def test_find_all_groups(self):
                     [('abb', 'bb'), ('abbb', 'bbb')]]),
           label='CheckAllNonEmptyGroups')
 
+  def test_find_all_groups_multiple_and_no_groups(self):
+    with TestPipeline() as p:
+      pcol = (p | beam.Create(['a=1 b=2 c=']))
+      assert_that(
+          pcol
+          | 'two groups' >> util.Regex.find_all(r'(\w)=(\d?)', util.Regex.ALL),
+          equal_to([[('a=1', 'a', '1'), ('b=2', 'b', '2'), ('c=', 'c', '')]]),
+          label='CheckTwoGroups')
+
+      assert_that(
+          pcol | 'no groups' >> util.Regex.find_all(
+              r'\w=\d', util.Regex.ALL, outputEmpty=False),
+          equal_to([[('a=1', ), ('b=2', )]]),
+          label='CheckNoGroups')

Review Comment:
   Added both: the two-group case with `outputEmpty=False`, and `r'\d*'` on `'1 
2'` with `outputEmpty` on and off.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to