derrickaw commented on code in PR #39126:
URL: https://github.com/apache/beam/pull/39126#discussion_r3483712693
##########
sdks/python/apache_beam/yaml/yaml_provider_unit_test.py:
##########
@@ -377,3 +372,260 @@ def test_create_mixed_types(self):
[('a', None), ('element', 1)],
[('a', 2), ('element', None)],
]))
+
+
+class YamlProvidersFlattenTest(unittest.TestCase):
+ def test_flatten_schema_merging(self):
+ with beam.Pipeline() as p:
+ pcoll1 = p | 'C1' >> beam.Create([beam.Row(a=1)])
+ pcoll2 = p | 'C2' >> beam.Create([beam.Row(b=2)])
+ res = {
+ 'first': pcoll1, 'second': pcoll2
+ } | yaml_provider.YamlProviders.Flatten()
+ assert_that(
+ res | beam.Map(lambda x: sorted(x._asdict().items())),
+ equal_to([
+ [('a', 1), ('b', None)],
+ [('a', None), ('b', 2)],
+ ]))
+
+ def test_flatten_single_pcoll(self):
+ with beam.Pipeline() as p:
+ pcoll = p | beam.Create([beam.Row(a=1)])
+ res = pcoll | yaml_provider.YamlProviders.Flatten()
+ assert_that(res, equal_to([beam.Row(a=1)]))
+
+ def test_flatten_empty(self):
+ with beam.Pipeline() as p:
+ res = p | yaml_provider.YamlProviders.Flatten()
+ assert_that(res, equal_to([]))
+
+ def test_flatten_single_pcoll(self):
+ with beam.Pipeline() as p:
+ pcoll = p | beam.Create([beam.Row(a=1)])
+ res = pcoll | yaml_provider.YamlProviders.Flatten()
+ assert_that(res, equal_to([beam.Row(a=1)]))
+
+ def test_flatten_empty(self):
+ with beam.Pipeline() as p:
+ res = p | yaml_provider.YamlProviders.Flatten()
+ assert_that(res, equal_to([]))
Review Comment:
Thanks
--
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]