-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(bigquery): document how to achieve higher write limit and add te…
…sts (#9574) * test(bigquery): add insert_rows*() tests w/o row IDs * Groom the insert_rows_json() method's docstring * docs: document how to achieve higher insert write limit * Make method names less confusing for insert IDs
- Loading branch information
Showing
5 changed files
with
206 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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 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
36 changes: 36 additions & 0 deletions
36
bigquery/samples/table_insert_rows_explicit_none_insert_ids.py
This file contains 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Copyright 2019 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
def table_insert_rows_explicit_none_insert_ids(client, table_id): | ||
|
||
# [START bigquery_table_insert_rows_explicit_none_insert_ids] | ||
# TODO(developer): Import the client library. | ||
# from google.cloud import bigquery | ||
|
||
# TODO(developer): Construct a BigQuery client object. | ||
# client = bigquery.Client() | ||
|
||
# TODO(developer): Set table_id to the ID of the model to fetch. | ||
# table_id = "your-project.your_dataset.your_table" | ||
|
||
table = client.get_table(table_id) # Make an API request. | ||
rows_to_insert = [(u"Phred Phlyntstone", 32), (u"Wylma Phlyntstone", 29)] | ||
|
||
errors = client.insert_rows( | ||
table, rows_to_insert, row_ids=[None] * len(rows_to_insert) | ||
) # Make an API request. | ||
if errors == []: | ||
print("New rows have been added.") | ||
# [END bigquery_table_insert_rows_explicit_none_insert_ids] |
33 changes: 33 additions & 0 deletions
33
bigquery/samples/tests/test_table_insert_rows_explicit_none_insert_ids.py
This file contains 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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Copyright 2019 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
from google.cloud import bigquery | ||
|
||
from .. import table_insert_rows_explicit_none_insert_ids as mut | ||
|
||
|
||
def test_table_insert_rows_explicit_none_insert_ids(capsys, client, random_table_id): | ||
|
||
schema = [ | ||
bigquery.SchemaField("full_name", "STRING", mode="REQUIRED"), | ||
bigquery.SchemaField("age", "INTEGER", mode="REQUIRED"), | ||
] | ||
|
||
table = bigquery.Table(random_table_id, schema=schema) | ||
table = client.create_table(table) | ||
|
||
mut.table_insert_rows_explicit_none_insert_ids(client, random_table_id) | ||
out, err = capsys.readouterr() | ||
assert "New rows have been added." in out |
This file contains 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