从Cloud Storage Json加载数据时出现BigQuery错误

时间:2017-12-20 10:15:11

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

我正在尝试从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)

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

1 个答案:

答案 0 :(得分:1)

至于你提供的代码,我看到一个错误,你错过了几个引用这个问题的LoadJobConfig的括号。错误位于以下行:

job_config2 = bigquery.LoadJobConfig()

试试这个,你的代码现在应该可以运行了。您可以在BigQuery Python API的官方文档中找到有关如何从云存储桶加载文件的更多信息和示例。