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 17
17
"""Simple application that performs a query with BigQuery."""
18
18
# [START all]
19
19
# [START create_client]
20
+ import uuid
21
+
20
22
from google .cloud import bigquery
21
23
22
24
23
25
def query_shakespeare ():
24
26
client = bigquery .Client ()
25
27
# [END create_client]
26
28
# [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 ()), """
29
30
#standardSQL
30
31
SELECT corpus AS title, COUNT(*) AS unique_words
31
32
FROM `publicdata.samples.shakespeare`
32
33
GROUP BY title
33
34
ORDER BY unique_words DESC
34
35
LIMIT 10""" )
35
36
36
- query_results .run ()
37
+ query_job .begin ()
38
+ query_job .result () # Wait for job to complete.
37
39
# [END run_query]
38
40
39
41
# [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 () :
43
45
print (row )
44
46
# [END print_results]
45
47
You can’t perform that action at this time.
0 commit comments