bcl*_*i4d 5 python google-bigquery
以下 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
Run Code Online (Sandbox Code Playgroud)
我正在从“将查询结果写入目标表”开始工作,但使用附加的“ALLOW_FIELD_ADDITION”和“ALLOW_FIELD_RELAXATION”配置设置(我认为)可以向目标表添加其他列。我尝试附加的数据的架构可能不是目标表架构的超集。而且我无法控制查询产生的项目的顺序,以防万一这些考虑因素很重要。
我正在使用标准 SQL。查询如下:
从“project.dataset.table”中选择“StudyDate”、“SeriesDate”、“AcquisitionDate” LIMIT 1
这是我第一次使用 BQ Python 库,所以如果我忽略了某些东西,我不会感到惊讶。
谢谢。
除了一个小错误之外,你做的都是对的。
\n\njob_config.schemaUpdateOptions是BigQuery Python API中不存在\xe2\x80\x99t 的字段。更改它job_config.schema_update_options,您的代码将按预期工作。
此外,这里还有几个示例,展示了如何使用 Python 修改 BigQuery 表架构。
\n| 归档时间: |
|
| 查看次数: |
9120 次 |
| 最近记录: |