[
https://issues.apache.org/jira/browse/BEAM-6695?focusedWorklogId=223477&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-223477
]
ASF GitHub Bot logged work on BEAM-6695:
----------------------------------------
Author: ASF GitHub Bot
Created on: 05/Apr/19 07:42
Start Date: 05/Apr/19 07:42
Worklog Time Spent: 10m
Work Description: robinyqiu commented on pull request #8206: [BEAM-6695]
Latest PTransform for Python SDK
URL: https://github.com/apache/beam/pull/8206#discussion_r272473918
##########
File path: sdks/python/apache_beam/transforms/combiners_test.py
##########
@@ -392,5 +394,92 @@ def test_global_fanout(self):
assert_that(result, equal_to([49.5]))
+class LatestTest(unittest.TestCase):
+
+ def test_globally(self):
+ l = [window.GlobalWindows.windowed_value(1, 100),
+ window.GlobalWindows.windowed_value(2, 200),
+ window.GlobalWindows.windowed_value(3, 300)]
+ with TestPipeline() as p:
+ pc = p | Create(l)
+ latest = pc | combine.Latest.Globally()
+ assert_that(latest, equal_to([3]))
+
+ def test_globally_empty(self):
+ l = []
+ with TestPipeline() as p:
+ pc = p | Create(l)
+ latest = pc | combine.Latest.Globally()
+ assert_that(latest, equal_to([None]))
+
+ def test_per_key(self):
+ l = [window.GlobalWindows.windowed_value(('a', 1), 100),
+ window.GlobalWindows.windowed_value(('b', 2), 200),
+ window.GlobalWindows.windowed_value(('a', 3), 300)]
+ with TestPipeline() as p:
+ pc = p | Create(l)
+ latest = pc | combine.Latest.PerKey()
+ assert_that(latest, equal_to([('a', 3), ('b', 2)]))
+
+ def test_per_key_empty(self):
+ l = []
+ with TestPipeline() as p:
+ pc = p | Create(l)
+ latest = pc | combine.Latest.PerKey()
+ assert_that(latest, equal_to([]))
+
+ def test_per_key_type_violation(self):
+ l_dict = [window.GlobalWindows.windowed_value({'a': 1}, 100),
+ window.GlobalWindows.windowed_value({'b': 2}, 100),
+ window.GlobalWindows.windowed_value({'a': 3}, 100)]
+ l_3_tuple = [window.GlobalWindows.windowed_value((1, 2, 3), 100),
+ window.GlobalWindows.windowed_value((4, 5, 6), 100),
+ window.GlobalWindows.windowed_value((7, 8, 9), 100)]
+ with self.assertRaises(TypeCheckError):
+ with TestPipeline() as p:
+ pc = p | Create(l_dict)
+ _ = pc | combine.Latest.PerKey()
+
+ with self.assertRaises(TypeCheckError):
+ with TestPipeline() as p:
+ pc = p | Create(l_3_tuple)
+ _ = pc | combine.Latest.PerKey()
+
+
+class LatestCombineFnTest(unittest.TestCase):
+
+ def setUp(self):
+ self.fn = combine.LatestCombineFn()
+
+ def test_create_accumulator(self):
+ accumulator = self.fn.create_accumulator()
+ self.assertEquals(accumulator, (None, window.MIN_TIMESTAMP))
+
+ def test_add_input(self):
+ accumulator = self.fn.create_accumulator()
+ element = (1, 100)
+ new_accumulator = self.fn.add_input(accumulator, element)
+ self.assertEquals(new_accumulator, (1, 100))
+
+ def test_merge_accumulators(self):
+ accumulators = [(1, 100),
+ (2, 200),
+ (3, 300)]
+ merged_accumulator = self.fn.merge_accumulators(accumulators)
+ self.assertEquals(merged_accumulator, (3, 300))
+
+ def test_extract_output(self):
+ accumulator = (1, 100)
+ output = self.fn.extract_output(accumulator)
+ self.assertEquals(output, 1)
+
+ def test_input_type_violation(self):
Review comment:
I think this test should go to `LatestTest` instead of `LatestCombineFnTest`?
----------------------------------------------------------------
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: 223477)
Time Spent: 2h 10m (was: 2h)
> 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: 2h 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)