Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BigQuery execution time

After I send a query to be executed in BigQuery, how can I find the execution time and other statistics about this job?

The Python API for BigQuery has a suggestive field timeline, but barely mentioned in the documentation. However, this method returns an empty iterable.

So far, I have been running this Python code, with the BigQuery Python API.

from google.cloud import bigquery

bq_client = bigquery.Client()
job = bq_client.query(some_sql_query, location="US")
ts = list(job.timeline)
if len(ts) > 0:
    for t in ts:
        print(t)
else:
    print('No timeline results ???')    # <-- no timeline results.
like image 744
Leonel Avatar asked Oct 27 '25 00:10

Leonel


1 Answers

When your job is "DONE", the BigQuery API returns a JobStatistics object (described here) that is accessible in Python through the attributes of your job object.

The available attrs are accessible here.

For accessing the time taken by your job you mainly have the job.created, job.started and job.ended attributes.

To come back to your code snippet, you can try something like this:

from google.cloud import bigquery

bq_client = bigquery.client()
job = bq_client.query(some_sql_query, location="US")

while job.running():
    print("Running..")
    sleep(0.1)

print("The job duration was {}".format(job.ended - job.started))
like image 130
Cylldby Avatar answered Oct 28 '25 14:10

Cylldby



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!