vachan-shetty commented on a change in pull request #15185:
URL: https://github.com/apache/beam/pull/15185#discussion_r679355415



##########
File path: sdks/python/apache_beam/io/gcp/bigquery.py
##########
@@ -1056,23 +1054,43 @@ def deserialize_rows(self, read_rows_response, reader):
 
   def read(self, range_tracker):
     storage_client = bq_storage.BigQueryReadClient()
-    read_rows_iterator = iter(storage_client.read_rows(self.read_stream_name))
-    read_rows_response = next(read_rows_iterator)
-    avro_schema = avro.schema.Parse(read_rows_response.avro_schema.schema)
-    reader = avroio.DatumReader(avro_schema)
-    while True:
-      # self.deserialize_rows(read_rows_response, reader)
-      decoder = avroio.BinaryDecoder(
-          io.BytesIO(read_rows_response.avro_rows.serialized_binary_rows))
-      current_row = 0
-      while current_row < read_rows_response.row_count:
-        self.deserialized_rows.append(reader.read(decoder))
-        current_row += 1
-      read_rows_response = next(read_rows_iterator, None)
-      if read_rows_response is None:
-        break
-
-    return iter(self.deserialized_rows)
+    row_reader = _ReadRowsResponseReader(
+        storage_client.read_rows(self.read_stream_name))
+    return iter(row_reader)
+
+
+class _ReadRowsResponseReader():
+  def __init__(self, read_rows_responses):
+    self.read_rows_iterator = iter(read_rows_responses)
+    self.read_rows_response = next(self.read_rows_iterator)

Review comment:
       There doesn't seem to be a simple way to handle this case in the 
`__next__` call. I've gone ahead and added some error handling to account for 
the possibility of an empty response. Added a test for the same.




-- 
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]


Reply via email to