8000 BQ: Use futures API for quickstart. · johnmanong/python-docs-samples@473fd9d · GitHub
[go: up one dir, main page]

Skip to content

Commit 473fd9d

Browse files
committed
BQ: Use futures API for quickstart.
1 parent 1e79287 commit 473fd9d

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

bigquery/cloud-client/simple_app.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,31 @@
1717
"""Simple application that performs a query with BigQuery."""
1818
# [START all]
1919
# [START create_client]
20+
import uuid
21+
2022
from google.cloud import bigquery
2123

2224

2325
def query_shakespeare():
2426
client = bigquery.Client()
2527
# [END create_client]
2628
# [START run_query]
27-
# See: https://cloud.google.com/bigquery/sql-reference/
28-
query_results = client.run_sync_query("""
29+
query_job = client.run_async_query(str(uuid.uuid4()), """
2930
#standardSQL
3031
SELECT corpus AS title, COUNT(*) AS unique_words
3132
FROM `publicdata.samples.shakespeare`
3233
GROUP BY title
3334
ORDER BY unique_words DESC
3435
LIMIT 10""")
3536

36-
query_results.run()
37+
query_job.begin()
38+
query_job.result() # Wait for job to complete.
3739
# [END run_query]
3840

3941
# [START print_results]
40-
rows = query_results.fetch_data()
41-
42-
for row in rows:
42+
destination_table = query_job.destination
43+
destination_table.reload()
44+
for row in destination_table.fetch_data():
4345
print(row)
4446
# [END print_results]
4547

0 commit comments

Comments
 (0)
0