Abacn commented on code in PR #17708:
URL: https://github.com/apache/beam/pull/17708#discussion_r891283913
##########
sdks/python/apache_beam/io/fileio_test.py:
##########
@@ -459,6 +459,36 @@ def test_write_to_single_file_batch(self):
assert_that(result, equal_to([row for row in self.SIMPLE_COLLECTION]))
+ def test_write_to_dynamic_destination(self):
+
+ dir = self._new_tempdir()
+
+ with TestPipeline() as p:
+ _ = (
+ p
+ | "Create" >> beam.Create(range(100))
+ | beam.Map(lambda x: str(x))
+ | fileio.WriteToFiles(
+ path=dir,
+ destination=lambda n: "odd" if int(n) % 2 else "even",
+ sink=fileio.TextSink,
+ file_naming=fileio.destination_prefix_naming("test")))
+
+ with TestPipeline() as p:
+ result = (
+ p
+ | fileio.MatchFiles(FileSystems.join(dir, '*'))
+ | fileio.ReadMatches()
+ | beam.Map(
+ lambda f: (
+ os.path.basename(f.metadata.path).split('-')[0],
+ sorted(map(int, f.read_utf8().strip().split('\n'))))))
+
+ assert_that(
+ result,
+ equal_to([('odd', list(range(1, 100, 2))),
Review Comment:
Yes, in direct runner it is not sorted either, thus a sorted() is used in
pipeline after read file.
--
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]