BigQuery 执行时间

Leo*_*nel 4 python google-bigquery

发送要在 BigQuery 中执行的查询后,如何查找有关该作业的执行时间和其他统计信息?

BigQuery 的 Python API 有一个暗示性的字段时间线,但在文档中几乎没有提及。但是,此方法返回一个空的可迭代对象。

到目前为止,我一直在使用 BigQuery Python API 运行此 Python 代码。

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.
Run Code Online (Sandbox Code Playgroud)

Cyl*_*dby 5

当您的作业“完成”时,BigQuery API 会返回一个 JobStatistics 对象(此处进行了描述),可通过作业对象的属性在 Python 中访问该对象。

可用的属性可在此处访问。

要访问作业所花费的时间,您主要有 job.created、job.started 和 job.ending 属性。

要回到您的代码片段,您可以尝试如下操作:

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))
Run Code Online (Sandbox Code Playgroud)