Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load schema json file to create table or job schema [closed]

If I already have the schema file, for example: schema.json. How can I load the file to create the table or job schema using the google-cloud-python API?

like image 403
Tuan Vu Avatar asked Nov 28 '16 20:11

Tuan Vu


People also ask

Which pattern describes source data that is moved into a BigQuery table in a single operation?

With batch loading, you load the source data into a BigQuery table in a single batch operation. For example, the data source could be a CSV file, an external database, or a set of log files.


1 Answers

You can try this solution:

import json
from google.cloud import bigquery

bigquerySchema = []
with open('schema.json') as f:
    bigqueryColumns = json.load(f)
    for col in bigqueryColumns:
        bigquerySchema.append(bigquery.SchemaField(col['name'], col['type']))

bigqueryClient = bigquery.Client()
tableRef = "myproject.mydataset.mytable"
table = bigquery.Table(tableRef, schema=bigquerySchema)
table = bigqueryClient.create_table(table)
like image 167
Soumendra Mishra Avatar answered Oct 30 '22 09:10

Soumendra Mishra