Skip to content

BigQuery: Add QueryResults.reload() function which calls getQueryResults #3506

@tswast

Description

@tswast

https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/getQueryResults

One of the things I learned when talking to the BigQuery API folks is that the recommended way to run a query is to create a query job and then call getQueryResults() until the jobComplete property is true.

The reason for this is that a call to get the job resource will return immediately, whereas getQueryResults will return after a timeout or the query is complete, whichever comes first. With getQueryResults users get their data faster.

This means the code for waiting for a query job to complete would change from

while True:
   query_job.reload()
    if query_job.state == 'DONE':
        return
    time.sleep(1)

to something like

query_results = query_job.results()
while not query_results.complete:
    query_results.reload()
    # No need for sleep, since reload should wait for timeout

Metadata

Metadata

Assignees

Labels

api: bigqueryIssues related to the BigQuery API.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions