robertwb 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_r387345481
##########
File path: sdks/python/apache_beam/runners/interactive/cache_manager.py
##########
@@ -167,20 +177,35 @@ 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)
+ with open(path, 'wb') as f:
+ for v in values:
+ sink.write_record(f, v)
Review comment:
This is not part of the public API for sinks. Instead, do
```
writer = sink.open_writer(init_result, path)
for v in values:
writer.write(v)
write_results.append(writer.close())
```
https://github.com/apache/beam/blob/release-2.18.0/sdks/python/apache_beam/io/iobase.py#L668
----------------------------------------------------------------
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