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

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

                Author: ASF GitHub Bot
            Created on: 01/May/19 14:22
            Start Date: 01/May/19 14:22
    Worklog Time Spent: 10m 
      Work Description: ttanay commented on pull request #8206: [BEAM-6695] 
Latest PTransform for Python SDK
URL: https://github.com/apache/beam/pull/8206#discussion_r280086154
 
 

 ##########
 File path: sdks/python/apache_beam/transforms/combiners.py
 ##########
 @@ -858,3 +863,62 @@ def merge_only(self, accumulators):
 
   def extract_only(self, accumulator):
     return self.combine_fn.extract_output(accumulator)
+
+
+class Latest(object):
+  """Combiners for computing the latest element"""
+
+  class Globally(ptransform.PTransform):
+    """Compute the element with the latest timestamp from a
+    PCollection."""
+
+    @staticmethod
+    def add_timestamp(element, timestamp=core.DoFn.TimestampParam):
+      return [(element, timestamp)]
+
+    def expand(self, pcoll):
+      return (pcoll
+              | core.ParDo(self.add_timestamp)
+              .with_output_types(Tuple[T, TimestampType])
+              | core.CombineGlobally(LatestCombineFn()))
+
+  class PerKey(ptransform.PTransform):
+    """Compute elements with the latest timestamp for each key
+    from a keyed PCollection"""
+
+    @staticmethod
+    def add_timestamp(element, timestamp=core.DoFn.TimestampParam):
+      _check_instance_type(KV[K, V], element)
 
 Review comment:
   Thank You @aaltay! I'll go through it and make the necessary changes.
 
----------------------------------------------------------------
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: 235802)
    Time Spent: 7h 10m  (was: 7h)

> Latest transform for Python SDK
> -------------------------------
>
>                 Key: BEAM-6695
>                 URL: https://issues.apache.org/jira/browse/BEAM-6695
>             Project: Beam
>          Issue Type: New Feature
>          Components: sdk-py-core
>            Reporter: Ahmet Altay
>            Assignee: Tanay Tummalapalli
>            Priority: Minor
>          Time Spent: 7h 10m
>  Remaining Estimate: 0h
>
> Add a PTransform} and Combine.CombineFn for computing the latest element 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/Latest.java



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to