Python 得到一个;架构更新无效。无法添加字段";从BQ开始,在配置中设置允许\字段\添加
以下python代码段在标题中产生错误:Python 得到一个;架构更新无效。无法添加字段";从BQ开始,在配置中设置允许\字段\添加,python,google-bigquery,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_confi
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
我正在从“将查询结果写入目标表”开始工作,但使用额外的“允许字段添加”和“允许字段松弛”配置设置(我认为)可以向目标表添加额外的列。
我试图附加的数据模式可能不是目标表模式的超集。我无法控制查询结果项的顺序,以防这些考虑因素起作用
我使用的是标准SQL。查询如下:
挑选
`StudyDate`,
`序列日期`,
`取得`
来自“project.dataset.table”`
限制1
这是我第一次使用BQ Python库,所以如果我忽略了一些东西,我不会感到惊讶
谢谢。除了一个小错误,你做得很对
job_config.schemaUpdateOptions
是中不存在的字段。将其更改为job\u config.schema\u update\u options
,您的代码将按预期工作
另外,演示如何使用Python修改BigQuery表模式。谢谢@llompalles。就是这样。我通过(错误地)查看REST API引用找到了schemaUpdateOptions属性,当我将它用作job_config对象的属性时,Python没有抱怨。@bcli4d您能用绿色勾号标记答案吗?这样我会更显眼,从而能够帮助像我这样与您相处的人吗?先谢谢你