Skip to content

Instantly share code, notes, and snippets.

@dotnwat
Last active October 18, 2017 17:05
Show Gist options
  • Save dotnwat/f66587f22a86409e91eac258471be059 to your computer and use it in GitHub Desktop.
Save dotnwat/f66587f22a86409e91eac258471be059 to your computer and use it in GitHub Desktop.
import sys
import time
import uuid
from google.cloud import bigquery
TABLE = "locations.samples"
QUERY = "SELECT {} FROM {} LIMIT {}"
# runtime params
limit = int(sys.argv[1])
columns = ",".join(sys.argv[2:])
# build query
query = QUERY.format(columns, TABLE, limit)
print query
start_time = time.time()
client = bigquery.Client()
query_job = client.run_async_query(str(uuid.uuid4()), query)
query_job.begin()
query_job.result()
result_table = query_job.destination
result_table.reload()
# materialize rows in memory
rows = [row for row in result_table.fetch_data()]
duration = time.time() - start_time
print duration, "secs"
assert(len(rows) == limit)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment