Abacn commented on code in PR #22130:
URL: https://github.com/apache/beam/pull/22130#discussion_r915149270
##########
sdks/python/apache_beam/io/filebasedsink.py:
##########
@@ -406,10 +417,33 @@ def __init__(self, sink, temp_shard_path):
self.sink = sink
self.temp_shard_path = temp_shard_path
self.temp_handle = self.sink.open(temp_shard_path)
+ self.num_records_written = 0
def write(self, value):
self.sink.write_record(self.temp_handle, value)
+ if self.sink.max_records_per_shard:
+ self.num_records_written += 1
+ return self.num_records_written >= self.sink.max_records_per_shard
+ if self.sink.max_bytes_per_shard:
+ return (
+ self.sink.byte_counter.bytes_written >=
self.sink.max_bytes_per_shard)
def close(self):
self.sink.close(self.temp_handle)
return self.temp_shard_path
+
+
+class _ByteCountingWriter:
Review Comment:
Found that io.BufferedWriter.write returns the number of bytes written
(https://docs.python.org/3.7/library/io.html#io.BufferedWriter.write) so
bytes_written can be traced directly in FileBasedSinkWriter.write
--
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]