From fd1cc21558832e0e660af5698bfe6edd4bdd7bda Mon Sep 17 00:00:00 2001 From: Jerjou Cheng Date: Thu, 29 Oct 2015 15:00:36 -0700 Subject: [PATCH] insertId is within the row, not the request. Fixes bug #134 --- bigquery/api/streaming.py | 10 ++++++---- bigquery/api/streaming_test.py | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/bigquery/api/streaming.py b/bigquery/api/streaming.py index c1549d735aa4..c0ad599d1e2a 100755 --- a/bigquery/api/streaming.py +++ b/bigquery/api/streaming.py @@ -35,11 +35,13 @@ # [START stream_row_to_bigquery] def stream_row_to_bigquery(bigquery, project_id, dataset_id, table_name, row, num_retries=5): - # Generate a unique row id so retries - # don't accidentally duplicate insert insert_all_data = { - 'insertId': str(uuid.uuid4()), - 'rows': [{'json': row}] + 'rows': [{ + 'json': row, + # Generate a unique id for each row so retries don't accidentally + # duplicate insert + 'insertId': str(uuid.uuid4()), + }] } return bigquery.tabledata().insertAll( projectId=project_id, diff --git a/bigquery/api/streaming_test.py b/bigquery/api/streaming_test.py index 1325a85b4abb..0f9fd01a52db 100644 --- a/bigquery/api/streaming_test.py +++ b/bigquery/api/streaming_test.py @@ -40,5 +40,6 @@ def test_stream_row_to_bigquery(self): self.table_id, num_retries=5) + print stdout results = stdout.getvalue().split('\n') self.assertIsNotNone(json.loads(results[0]))