pabloem commented on a change in pull request #11005: [BEAM-8335] Modify the
StreamingCache to subclass the CacheManager
URL: https://github.com/apache/beam/pull/11005#discussion_r391139425
##########
File path: sdks/python/apache_beam/runners/interactive/cache_manager.py
##########
@@ -167,20 +196,38 @@ def load_pcoder(self, *labels):
self._saved_pcoders[self._path(*labels)])
def read(self, *labels):
+ # Return an iterator to an empty list if it doesn't exist.
if not self.exists(*labels):
- return [], -1
+ return iter([]), -1
- source = self.source(*labels)
+ # Otherwise, return a generator to the cached PCollection.
+ source = self._source(*labels)
range_tracker = source.get_range_tracker(None, None)
- result = list(source.read(range_tracker))
+ reader = source.read(range_tracker)
version = self._latest_version(*labels)
- return result, version
+ return reader, version
+
+ def write(self, values, *labels):
+ sink = self._sink(*labels)
+ path = self._path(*labels)
+
+ init_result = sink.initialize_write()
+ writer = sink.open_writer(init_result, path)
+ for v in values:
+ writer.write(v)
+ writer.close()
def source(self, *labels):
+ return beam.io.Read(self._source(*labels))
+
+ def sink(self, labels):
+ return beam.io.Write(self._sink(*labels))
+
+ def _source(self, *labels):
return self._reader_class(
self._glob_path(*labels), coder=self.load_pcoder(*labels))._source
- def sink(self, *labels):
+ def _sink(self, *labels):
return self._writer_class(
Review comment:
it seems like you can just return the result of `self._writer_class(...)`
all the way. This is a PTransform, so it is consistent with the itnerface
(instead of re-wrapping the source / sink)
----------------------------------------------------------------
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]
With regards,
Apache Git Services