Jav*_*ini 4 python google-bigquery
我最近在使用 Python API 时收到以下 BigQuery 错误:
google.api_core.exceptions.BadRequest:无法为脚本设置 400 configuration.query.destinationTable
这是我使用的功能:
def execute_bigquery_sql(query, dataset_id, table_id, use_legacy_sql=True, write_disposition='WRITE_TRUNCATE'):
client = bigquery.Client()
job_config = bigquery.QueryJobConfig()
job_config.use_legacy_sql = use_legacy_sql
print("table_id: {table_id}".format(table_id=table_id))
print("dataset_id: {dataset_id}".format(dataset_id=dataset_id))
if table_id:
table_ref = client.dataset(dataset_id).table(table_id)
print("table_ref: {table_ref}".format(table_ref=table_ref))
job_config.destination = table_ref
job_config.write_disposition = write_disposition
job_config.allow_large_results = True
job_config.createDisposition = "CREATE_IF_NEEDED"
query_job = client.query(query,job_config=job_config)
results = query_job.result() # Waits for job to complete.
Run Code Online (Sandbox Code Playgroud)
有谁知道可能会发生什么和解决方法?
感谢您的回复,评论确实是在正确的方向。在 BigQuery 脚本中意味着https://cloud.google.com/bigquery/docs/reference/standard-sql/scripting。
这是不允许的,我的查询有:
DECLARE capital int64 default 10000000;
Run Code Online (Sandbox Code Playgroud)
因此,在我的情况下,删除上面的行是解决方法。
有趣的是,即使在 Web 界面中
错误是自我描述的。脚本不允许设置目标表 - 相反,您应该使用 DML/DDL
解决方法是重置 job_config,其中没有目标表
归档时间: |
|
查看次数: |
6373 次 |
最近记录: |