From 4bfaa9884cd320547d053583d4be8ba27ab15d55 Mon Sep 17 00:00:00 2001 From: Tim Swast Date: Tue, 8 Aug 2017 12:11:16 -0700 Subject: [PATCH] BQ: Use futures API for quickstart. --- samples/snippets/simple_app.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/samples/snippets/simple_app.py b/samples/snippets/simple_app.py index 6db856839..9bca432ef 100644 --- a/samples/snippets/simple_app.py +++ b/samples/snippets/simple_app.py @@ -17,6 +17,8 @@ """Simple application that performs a query with BigQuery.""" # [START all] # [START create_client] +import uuid + from google.cloud import bigquery @@ -24,8 +26,7 @@ def query_shakespeare(): client = bigquery.Client() # [END create_client] # [START run_query] - # See: https://cloud.google.com/bigquery/sql-reference/ - query_results = client.run_sync_query(""" + query_job = client.run_async_query(str(uuid.uuid4()), """ #standardSQL SELECT corpus AS title, COUNT(*) AS unique_words FROM `publicdata.samples.shakespeare` @@ -33,13 +34,14 @@ def query_shakespeare(): ORDER BY unique_words DESC LIMIT 10""") - query_results.run() + query_job.begin() + query_job.result() # Wait for job to complete. # [END run_query] # [START print_results] - rows = query_results.fetch_data() - - for row in rows: + destination_table = query_job.destination + destination_table.reload() + for row in destination_table.fetch_data(): print(row) # [END print_results]