1 回答
TA贡献1871条经验 获得超13个赞
这是遍历脚本的快速示例。在此示例中,您的父作业属于脚本类型,它由两个都是 select 语句的子作业组成。父作业完成后,您可以调用list_jobs父过滤器来查找子作业并询问它们的结果。子作业不嵌套,因此您只需担心父作业下的一级子作业。
def multi_statement_script():
from google.cloud import bigquery
bqclient = bigquery.Client()
query = """ SELECT 1;
SELECT 2;
"""
parent_query = bqclient.query(query)
# wait for parent job to finish (which completes when all children are done)
parent_query.result()
print("parent job {}".format(parent_query.job_id))
children = bqclient.list_jobs(parent_job=parent_query.job_id)
# note the jobs are enumerated newest->oldest, so the reverse
# ordering specified in the script
for child in children:
print("job {}".format(child.job_id))
rows = list(child.result())
print(rows)
添加回答
举报