#If you do not set the service account, you will get an authentication error.
# export GOOGLE_APPLICATION_CREDENTIALS=/path/to/credential
from google.cloud import bigquery
client = bigquery.Client('project')
table_ref = client.dataset('dataset').table('table$20200101') #partition
job_config = bigquery.LoadJobConfig()
job_config.write_disposition = bigquery.WriteDisposition.WRITE_TRUNCATE #Overwrite
job_config.source_format = bigquery.SourceFormat.NEWLINE_DELIMITED_JSON # JSON
# job_config.ignore_unknown_values = True #Uncomment if unknown value is allowed
uri = 'gs://bucket/path/*.gz' #Specify everything under the directory
load_job = client.load_table_from_uri(
uri, table_ref, job_config=job_config
)
load_job.result()
print("Job finished.")
Recommended Posts