-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathload.py
More file actions
30 lines (20 loc) · 735 Bytes
/
Copy pathload.py
File metadata and controls
30 lines (20 loc) · 735 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import os
from google.cloud import bigquery
def main():
# Construct a BigQuery client object.
client = bigquery.Client()
table_id = os.getenv('TABLE_ID')
job_config = bigquery.LoadJobConfig(
source_format=bigquery.SourceFormat.NEWLINE_DELIMITED_JSON, autodetect=True,
)
with open('trace.json', "rb") as source_file:
job = client.load_table_from_file(source_file, table_id, job_config=job_config)
job.result() # Waits for the job to complete.
table = client.get_table(table_id) # Make an API request.
print(
"Loaded {} rows and {} columns to {}".format(
table.num_rows, len(table.schema), table_id
)
)
if __name__ == '__main__':
main()