以下 python 代码片段会产生标题中的错误:
job_config = bigquery.QueryJobConfig()
# Set the destination table
table_ref = client.dataset(args.bq_dataset_id).table(args.bq_cum_table)
job_config.destination = table_ref
job_config.write_disposition = 'WRITE_APPEND'
job_config.schemaUpdateOptions = ['ALLOW_FIELD_ADDITION', 'ALLOW_FIELD_RELAXATION']
# Start the query, passing in the extra configuration.
query_job = client.query(
sqlstr,
# Location must match that of the dataset(s) referenced in the query
# and of the destination table.
location="US",
job_config=job_config,
) # API request - starts the query
query_job.result() # Wait for the query to finish
我正在从“将查询结果写入目标表”开始工作here https://googleapis.github.io/google-cloud-python/latest/bigquery/usage/queries.html,但通过附加的“ALLOW_FIELD_ADDITION”和“ALLOW_FIELD_RELAXATION”配置设置(我认为)可以向目标表添加附加列。
我尝试附加的数据的架构可能不是目标表架构的超集。而且我无法控制查询产生的项目的顺序,以防万一这些考虑因素很重要。
我正在使用标准 SQL。查询如下:
选择
`学习日期`,
`系列日期`,
`获取日期`
来自`project.dataset.table`
限制1
这是我第一次使用 BQ Python 库,因此如果我忽略了某些内容,我不会感到惊讶。
Thanks.
除了一个小错误之外,你做的都是对的。
job_config.schemaUpdateOptions
是一个不存在的字段BigQuery Python API https://googleapis.github.io/google-cloud-python/latest/bigquery/generated/google.cloud.bigquery.job.QueryJobConfig.html#google.cloud.bigquery.job.QueryJobConfig.schema_update_options。将其更改为job_config.schema_update_options
并且您的代码将按预期工作。
Also, 这是几个例子 https://cloud.google.com/bigquery/docs/managing-table-schemas展示如何使用 Python 修改 BigQuery 表架构。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)