Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitae647eb

Browse files
authored
docs: recommend insert_rows_json to avoid call to tables.get (#258)
* docs: recommend insert_rows_json to avoid call to tables.getSince tables.get has a much lower QPS than tabledata.insertAll, we wantto avoid recommending a pattern that requires fetching a table schema.If developers convert to a dictionary of the correct JSON format, notable schema is required.* update comments
1 parentd24b5bb commitae647eb

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

‎samples/table_insert_rows.py‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,22 @@
1616
deftable_insert_rows(table_id):
1717

1818
# [START bigquery_table_insert_rows]
19-
2019
fromgoogle.cloudimportbigquery
2120

2221
# Construct a BigQuery client object.
2322
client=bigquery.Client()
2423

25-
# TODO(developer): Set table_id to the ID ofthe modeltofetch.
24+
# TODO(developer): Set table_id to the ID oftabletoappend to.
2625
# table_id = "your-project.your_dataset.your_table"
2726

28-
table=client.get_table(table_id)# Make an API request.
29-
rows_to_insert= [(u"Phred Phlyntstone",32), (u"Wylma Phlyntstone",29)]
27+
rows_to_insert= [
28+
{u"full_name":u"Phred Phlyntstone",u"age":32},
29+
{u"full_name":u"Wylma Phlyntstone",u"age":29},
30+
]
3031

31-
errors=client.insert_rows(table,rows_to_insert)# Make an API request.
32+
errors=client.insert_rows_json(table_id,rows_to_insert)# Make an API request.
3233
iferrors== []:
3334
print("New rows have been added.")
35+
else:
36+
print("Encountered errors while inserting rows: {}".format(errors))
3437
# [END bigquery_table_insert_rows]

‎samples/table_insert_rows_explicit_none_insert_ids.py‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,24 @@
1616
deftable_insert_rows_explicit_none_insert_ids(table_id):
1717

1818
# [START bigquery_table_insert_rows_explicit_none_insert_ids]
19-
2019
fromgoogle.cloudimportbigquery
2120

2221
# Construct a BigQuery client object.
2322
client=bigquery.Client()
2423

25-
# TODO(developer): Set table_id to the ID ofthe modeltofetch.
24+
# TODO(developer): Set table_id to the ID oftabletoappend to.
2625
# table_id = "your-project.your_dataset.your_table"
2726

28-
table=client.get_table(table_id)# Make an API request.
29-
rows_to_insert= [(u"Phred Phlyntstone",32), (u"Wylma Phlyntstone",29)]
27+
rows_to_insert= [
28+
{u"full_name":u"Phred Phlyntstone",u"age":32},
29+
{u"full_name":u"Wylma Phlyntstone",u"age":29},
30+
]
3031

31-
errors=client.insert_rows(
32-
table,rows_to_insert,row_ids=[None]*len(rows_to_insert)
32+
errors=client.insert_rows_json(
33+
table_id,rows_to_insert,row_ids=[None]*len(rows_to_insert)
3334
)# Make an API request.
3435
iferrors== []:
3536
print("New rows have been added.")
37+
else:
38+
print("Encountered errors while inserting rows: {}".format(errors))
3639
# [END bigquery_table_insert_rows_explicit_none_insert_ids]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp