【发布时间】:2018-02-07 08:50:12
【问题描述】:
我目前正在使用 Bigquery 作业来调整一些数据并将其加载到其他表中。
我的 bigquery 作业使用查询作业从表中读取,然后将其写入其他表中。作业执行成功,作业状态已完成,但已加载任何行。
这是代码:
table_id_from = "table_from"
table_ref_to = bigquery_client.dataset('format').table("table_to")
job_config = bigquery.LoadJobConfig()
job_config.create_disposition = 'NEVER'
job_config.destination = table_ref_to_format
job_config.write_disposition = 'WRITE_APPEND'
job_config.use_legacy_sql = False
# Start the query, passing in the extra configuration.
query = """SELECT id, name, short_name,
subdomain, address, address2, department, state, zip
from staging.%s;""" %(table_id_from)
query_job = bigquery_client.query(query, job_config=job_config)
rows_from_staging = list(query_job) # Waits for the query to finish
print(len(rows_from_staging))
# assert query_job.state == 'RUNNING'
# assert query_job.job_type == 'query'
iterator = bigquery_client.list_rows(
table_ref_to_format, selected_fields=[bigquery.SchemaField('id', 'INTEGER')])
rows = list(iterator)
print(len(rows))
print(query_job.state)
query_job.result()
第一部分的结果,当从表中读取时,打印 len 3。另一方面,当查询目标表时,它不读取任何内容并打印 0 作为行的 len。
3
0
DONE
发生了什么?如果出现问题,我希望给我一个错误,但它运行成功。有什么帮助吗?
【问题讨论】: