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

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

                Author: ASF GitHub Bot
            Created on: 30/Jul/19 14:47
            Start Date: 30/Jul/19 14:47
    Worklog Time Spent: 10m 
      Work Description: robertwb commented on pull request #9168: [BEAM-7840] 
Provide MapTuple and FlatMapTuple for Python 3 users.
URL: https://github.com/apache/beam/pull/9168#discussion_r308766500
 
 

 ##########
 File path: sdks/python/apache_beam/pipeline_test.py
 ##########
 @@ -168,6 +168,35 @@ def test_flatmap_builtin(self):
     assert_that(pcoll4, equal_to([11, 12, 12, 12, 13]), label='pcoll4')
     pipeline.run()
 
+  def test_maptuple_builtin(self):
+    pipeline = TestPipeline()
+    pcoll = pipeline | Create([('e1', 'e2')])
+    side1 = beam.pvalue.AsSingleton(pipeline | 'side1' >> Create(['s1']))
+    side2 = beam.pvalue.AsSingleton(pipeline | 'side2' >> Create(['s2']))
+
+    # A test function with a tuple input, an auxiliary parameter,
+    # and some side inputs.
+    fn = lambda e1, e2, t=DoFn.TimestampParam, s1=None, s2=None: (
+        e1, e2, t, s1, s2)
+    assert_that(pcoll | 'NoSides' >> beam.core.MapTuple(fn),
+                equal_to([('e1', 'e2', MIN_TIMESTAMP, None, None)]),
+                label='NoSidesCheck')
+    assert_that(pcoll | 'StaticSides' >> beam.core.MapTuple(fn, 's1', 's2'),
+                equal_to([('e1', 'e2', MIN_TIMESTAMP, 's1', 's2')]),
+                label='StaticSidesCheck')
+    assert_that(pcoll | 'DynamicSides' >> beam.core.MapTuple(fn, side1, side2),
+                equal_to([('e1', 'e2', MIN_TIMESTAMP, 's1', 's2')]),
+                label='DynamicSidesCheck')
+    assert_that(pcoll | 'MixedSides' >> beam.core.MapTuple(fn, s2=side2),
+                equal_to([('e1', 'e2', MIN_TIMESTAMP, None, 's2')]),
+                label='MixedSidesCheck')
+
+    # FlatMapTuple is similar.
+    assert_that(pcoll | 'FlatMap' >> beam.core.FlatMapTuple(fn, s2=side2),
 
 Review comment:
   Done.
 
----------------------------------------------------------------
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: 285011)
    Time Spent: 0.5h  (was: 20m)

> Create MapTuple and FlatMapTuple to ease migration to Python 3.
> ---------------------------------------------------------------
>
>                 Key: BEAM-7840
>                 URL: https://issues.apache.org/jira/browse/BEAM-7840
>             Project: Beam
>          Issue Type: Test
>          Components: sdk-py-core
>            Reporter: Robert Bradshaw
>            Assignee: Robert Bradshaw
>            Priority: Major
>             Fix For: 2.15.0
>
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> These are like Map and FlatMap but expand out tuple input elements across
> several arguments. This will be useful as tuple argument unpacking has been
> removed in Python 3. Instead of having to convert
>     Map(lambda (k, v): expresion(k, v))
> into
>     Map(lambda k_v: expression(k_v[0], k_v[1]))
> one can now write
>     MapTuple(lambda k, v: expression(k, v))



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

Reply via email to