无法使用BigQuery Python API设置目标表 [英] Cannot set destination table with BigQuery Python API

查看:146
本文介绍了无法使用BigQuery Python API设置目标表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在使用Python API时遇到以下BigQuery错误:

I'm recently getting the following BigQuery error when using the Python API:

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.

有人知道会发生什么情况以及解决方法吗?

Does anyone knows what might be happening and a workaround?

推荐答案

感谢您的答复,评论的方向确实正确.在BigQuery中,脚本表示 https://cloud.google.com/bigquery/docs/reference/standard-sql/scripting.

Thanks for the responses, comments were indeed in the right direction. In BigQuery scripting means https://cloud.google.com/bigquery/docs/reference/standard-sql/scripting.

那是不允许的,我的查询有:

And that is what is not allowed, and my query had:

DECLARE capital int64 default 10000000;

因此,就我而言,删除上面的行是解决问题的方法.

So, removing the line above was the fix in my case.

有趣的是,即使在Web界面中

Interesting thing is that even in the web interface

  • 如果使用脚本,则该界面将不允许保存到表中:

  • 相反,当不使用脚本语句时,您应该看到:
  • In contrast, when not using script statements, you should see:

这篇关于无法使用BigQuery Python API设置目标表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆