Created
January 17, 2023 14:58
-
-
Save timhberry/1f5543b38222e8bd5c26c3f68247b35f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from google.cloud import bigquery | |
dataset = "btlearningpath" | |
table = "city_speeds_from_function" | |
def add_to_bq(data, context): | |
source_bucket = data['bucket'] | |
source_file = data['name'] | |
uri = 'gs://{}/{}'.format(source_bucket, source_file) | |
client = bigquery.Client() | |
dataset_ref = client.dataset(dataset) | |
job_config = bigquery.LoadJobConfig() | |
job_config.autodetect = True | |
job_config.source_format = bigquery.SourceFormat.CSV | |
job_config.write_disposition = bigquery.WriteDisposition.WRITE_APPEND | |
load_job = client.load_table_from_uri( | |
uri, | |
dataset_ref.table(table), | |
job_config=job_config | |
) | |
print('Starting job {}'.format(load_job.job_id)) | |
load_job.result() | |
print('Job finished.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment