Skip to content

Instantly share code, notes, and snippets.

@timhberry
Created January 17, 2023 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timhberry/1f5543b38222e8bd5c26c3f68247b35f to your computer and use it in GitHub Desktop.
Save timhberry/1f5543b38222e8bd5c26c3f68247b35f to your computer and use it in GitHub Desktop.
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