Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
BigQuery: Add Client.insert_rows, deprecate Client.create_rows#4657
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
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -23,6 +23,7 @@ | ||
| need to be deleted during teardown. | ||
| """ | ||
| import json | ||
| import time | ||
| import pytest | ||
| @@ -64,9 +65,9 @@ def to_delete(client): | ||
| doomed = [] | ||
| yield doomed | ||
| for item in doomed: | ||
| if isinstance(item, bigquery.Dataset): | ||
| if isinstance(item, (bigquery.Dataset, bigquery.DatasetReference)): | ||
| client.delete_dataset(item) | ||
| elif isinstance(item, bigquery.Table): | ||
| elif isinstance(item, (bigquery.Table, bigquery.TableReference)): | ||
| client.delete_table(item) | ||
| else: | ||
| item.delete() | ||
| @@ -414,28 +415,28 @@ def test_update_table_multiple_properties(client, to_delete): | ||
| # [END update_table_multiple_properties] | ||
| def test_table_create_rows(client, to_delete): | ||
| def test_table_insert_rows(client, to_delete): | ||
| """Insert / fetch table data.""" | ||
| DATASET_ID = 'table_create_rows_dataset_{}'.format(_millis()) | ||
| TABLE_ID = 'table_create_rows_table_{}'.format(_millis()) | ||
| dataset = bigquery.Dataset(client.dataset(DATASET_ID)) | ||
| dataset_id = 'table_insert_rows_dataset_{}'.format(_millis()) | ||
| table_id = 'table_insert_rows_table_{}'.format(_millis()) | ||
| dataset = bigquery.Dataset(client.dataset(dataset_id)) | ||
| dataset = client.create_dataset(dataset) | ||
| to_delete.append(dataset) | ||
| table = bigquery.Table(dataset.table(TABLE_ID), schema=SCHEMA) | ||
| table = bigquery.Table(dataset.table(table_id), schema=SCHEMA) | ||
| table = client.create_table(table) | ||
| to_delete.insert(0, table) | ||
| # [START table_create_rows] | ||
| ROWS_TO_INSERT = [ | ||
| # [START table_insert_rows] | ||
| rows_to_insert = [ | ||
| (u'Phred Phlyntstone', 32), | ||
| (u'Wylma Phlyntstone', 29), | ||
| ] | ||
| errors = client.create_rows(table, ROWS_TO_INSERT) # API request | ||
| errors = client.insert_rows(table, rows_to_insert) # API request | ||
| assert errors == [] | ||
| # [END table_create_rows] | ||
| # [END table_insert_rows] | ||
| def test_load_table_from_file(client, to_delete): | ||
| @@ -600,9 +601,20 @@ def test_extract_table(client, to_delete): | ||
| to_delete.append(dataset) | ||
| table_ref = dataset.table('person_ages') | ||
| table = client.create_table(bigquery.Table(table_ref, schema=SCHEMA)) | ||
| to_delete.insert(0, table) | ||
| client.create_rows(table, ROWS) | ||
| to_insert = [ | ||
| {'full_name': name, 'age': age} | ||
| for name, age in ROWS | ||
| ] | ||
| rows = [json.dumps(row) for row in to_insert] | ||
| body = six.StringIO('{}\n'.format('\n'.join(rows))) | ||
| job_config = bigquery.LoadJobConfig() | ||
| job_config.write_disposition = 'WRITE_TRUNCATE' | ||
| job_config.source_format = 'NEWLINE_DELIMITED_JSON' | ||
| job_config.schema = SCHEMA | ||
| to_delete.insert(0, table_ref) | ||
| # Load a table using a local JSON file from memory. | ||
| client.load_table_from_file( | ||
| body, table_ref, job_config=job_config).result() | ||
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page. | ||
| bucket_name = 'extract_person_ages_job_{}'.format(_millis()) | ||
| # [START extract_table] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.