-
Notifications
You must be signed in to change notification settings - Fork 623
Follow up fix for merging errors from batch BigQuery inserts (#1348). #1350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -370,7 +370,7 @@ def insert(self, inserts): | |
| A json explained here: | ||
| https://cloud.google.com/bigquery/docs/reference/rest/v2/tabledata/insertAll | ||
| """ | ||
| result = None | ||
| result = {} | ||
| for i in range(0, len(inserts), INSERT_BATCH_SIZE): | ||
| response = self._insert_batch( | ||
| inserts[i:min(len(inserts), i + INSERT_BATCH_SIZE)]) | ||
|
|
@@ -379,8 +379,18 @@ def insert(self, inserts): | |
| time.sleep(1) | ||
|
|
||
| if not result: | ||
| # Use result from the first batch, appending errors from the rest. | ||
| result = response | ||
| else: | ||
| result['insertErrors'].extend(response['insertErrors']) | ||
| # If there are new errors from the current batch, append to the result. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel the else makes the flow of the logic a bit confusing here. We can probably just continue after line 383 and unindent the rest.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks, done! |
||
| new_errors = response.get('insertErrors') | ||
| if not new_errors: | ||
| continue | ||
|
|
||
| # Apparently result may not have errors, be careful. | ||
| if result.get('insertErrors'): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: we can do this much more concisely like so: result.setdefault('insertErrors', []).extend(new_errors)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. beautiful, done! |
||
| result['insertErrors'].extend(new_errors) | ||
| else: | ||
| result['insertErrors'] = new_errors | ||
|
|
||
| return result | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we don't capture result (non-errors) from other parts of query response. This seems weird. @oliverchang for review as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There isn't anything else useful as per the documentation: https://cloud.google.com/bigquery/docs/reference/rest/v2/tabledata/insertAll
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed that there is nothing much else in the returned values.