Skip to content

Commit

Permalink
insertId is within the row, not the request.
Browse files Browse the repository at this point in the history
Fixes bug #134
  • Loading branch information
Jerjou Cheng committed Oct 29, 2015
1 parent 1ff6a5b commit fd1cc21
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
10 changes: 6 additions & 4 deletions bigquery/api/streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions bigquery/api/streaming_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]))

0 comments on commit fd1cc21

Please sign in to comment.