I'm trying to get all results from a BQ query but I can only get 100 results.
Given the borked python BQ iterator API what's the best way to do this?
based on these docs: https://cloud.google.com/bigquery/docs/paging-results
I have all this code (to do something really basic) but still only get 100 results...
I must be missing something in the API, this should not be so complicated.
bqc = bigquery.Client(credentials=bq_creds, project=bq_creds.project_id)
def query(qstring, getall=True):
'''run a time query string'''
logger.info('query>> %s', qstring)
try:
job = bqc.query(qstring)
result = job.result()
except Exception as err:
logging.error('failed BQ job %s', err)
raise err
if getall:
result = get_all(result, job)
return result
def get_all(cursor, job):
'''unwind the bq data'''
destination = job.destination
destination = bqc.get_table(destination)
# Download rows.
# The client library automatically handles pagination.
rows = bqc.list_rows(destination, max_results=5000)
data = []
for row in rows:
data.append(row)
logging.info('get_all rows: %s', len(data))
return data
(Then a follow-on question is how to make this BQ data JSON serializable)