Manuel Valero
Manuel Valero

Reputation: 445

BigQuery error while loading data from Cloud Storage Json

I'm trying to load data to BigQuery from a Cloud Storage JSON.

I use the BigQuery API.

This is the error I got:

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

And this is the code:

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)

Am I missing anything? Any help?

Upvotes: 0

Views: 712

Answers (1)

dsesto
dsesto

Reputation: 8178

As for the code you provided, I see an error where you are missing a couple of parenthesis referring to this LoadJobConfig that is causing you trouble. The error is in the following line:

job_config2 = bigquery.LoadJobConfig()

Try that and your code should work now. You can find more information and examples on how to do load files from a Cloud Storage bucket in the official documentation for the BigQuery Python API.

Upvotes: 1

Related Questions