Last active
October 18, 2017 17:05
-
-
Save dotnwat/f66587f22a86409e91eac258471be059 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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