Skip to content

Commit

Permalink
BQ: Use futures API for quickstart.
Browse files Browse the repository at this point in the history
  • Loading branch information
tswast committed Aug 8, 2017
1 parent 8d19f90 commit 4bfaa98
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions samples/snippets/simple_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,31 @@
"""Simple application that performs a query with BigQuery."""
# [START all]
# [START create_client]
import uuid

from google.cloud import bigquery


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`
GROUP BY title
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]

Expand Down

0 comments on commit 4bfaa98

Please sign in to comment.