【问题标题】:BigQuery error while loading data from Cloud Storage Json从 Cloud Storage Json 加载数据时出现 BigQuery 错误
【发布时间】:2017-12-20 10:15:11
【问题描述】:

我正在尝试将数据从 Cloud Storage JSON 加载到 BigQuery。

我使用 BigQuery API。

这是我得到的错误:

TypeError: unbound method to_api_repr() must be called with LoadJobConfig instance as first argument (got nothing instead)

这是代码:

from google.cloud import bigquery


bigquery_client = bigquery.Client(project='test')
table_ref = bigquery_client.dataset('test').table('test_table')
GS_URL = 'gs://{}/raw/test/test.json'.format('bucket_test')
job_id_prefix2 = 'copy_test'
job_config2 = bigquery.LoadJobConfig
job_config2.create_disposition = 'NEVER'
job_config2.skip_leading_rows = 0
job_config2.source_format = 'NEWLINE_DELIMITED_JSON'
job_config2.write_disposition = 'WRITE_APPEND'

load_job = bigquery_client.load_table_from_uri(
    GS_URL,
    table_ref,
    job_id="job",
    job_id_prefix=job_id_prefix2,
    job_config=job_config2)  # API request

assert load_job.state == 'RUNNING'
assert load_job.job_type == 'load'


load_job.result()  # Waits for table load to complete.


assert load_job.state == 'DONE'
assert load_job.job_id.startswith(job_id_prefix2)

我错过了什么吗?有什么帮助吗?

【问题讨论】:

    标签: python json google-bigquery google-cloud-storage


    【解决方案1】:

    至于您提供的代码,我看到一个错误,您缺少一对引用此LoadJobConfig 的括号,这给您带来了麻烦。错误在以下行:

    job_config2 = bigquery.LoadJobConfig()
    

    尝试一下,您的代码现在应该可以工作了。您可以在BigQuery Python API 的官方文档中找到有关如何从 Cloud Storage 存储桶加载文件的更多信息和示例。

    【讨论】:

      猜你喜欢
      • 2017-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-14
      • 2013-05-24
      • 2020-02-15
      • 2014-08-07
      相关资源
      最近更新 更多