gfw.common.bigquery.QueryResult#
- class QueryResult(query_job, row_iterator)[source]#
Wrapper around
bigquery.job.QueryJobwith access to results.This class encapsulates
query_jobandrow_iteratorinstances, exposing rows via iteration and providing convenience methods likeiter_as_dicts()andtolist().- Parameters:
query_job (QueryJob) – The original
QueryJob, which can be used to access job metadata such as session IDs, job statistics, and more.row_iterator (RowIterator) – The
RowIteratorreturned by the query job.
Example
result = bq_client.run_query("SELECT * FROM my_table") # Iterate raw rows for row in result: print(row) # Iterate as dicts for row in result.iter_as_dicts(): print(row) # Materialize rows = result.tolist() rows_as_dicts = result.tolist(as_dicts=True) # Access job metadata print(result.query_job.job_id) print(result.session_id)
Methods
Iterates over rows as dictionaries.
Materializes all rows into a list.
Attributes
Returns the
session_idof the job, orNoneif not available.The encapsulated
QueryJobinstance.The
RowIteratorreturned by the query job.- query_job: QueryJob#
The encapsulated
QueryJobinstance.
- row_iterator: RowIterator#
The
RowIteratorreturned by the query job.