File tree Expand file tree Collapse file tree 1 file changed +8
-6
lines changed
Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change 1717"""Simple application that performs a query with BigQuery."""
1818# [START all]
1919# [START create_client]
20+ import uuid
21+
2022from google .cloud import bigquery
2123
2224
2325def 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
You can’t perform that action at this time.
0 commit comments