Skip to content
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

BigQuery insert: improve the readability of the merge insertErrors logic. #1355

Merged
merged 2 commits into from
Jan 21, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions src/python/google_cloud_utils/big_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,16 +383,14 @@ def insert(self, inserts):
if not result:
# Use result from the first batch, appending errors from the rest.
result = response
else:
# If there are new errors from the current batch, append to the result.
new_errors = response.get('insertErrors')
if not new_errors:
continue

# Apparently result may not have errors, be careful.
if result.get('insertErrors'):
result['insertErrors'].extend(new_errors)
else:
result['insertErrors'] = new_errors
continue

# If there are new errors from the current batch, append to the result.
new_errors = response.get('insertErrors')
if not new_errors:
continue

# Apparently result may not have errors, use |setdefault| to be careful.
result.setdefault('insertErrors', []).extend(new_errors)

return result