Mikkel84
11/10/2018 - 10:44 AM

[Upload JSON-file to GCP BigQuery] #GCP #Google #JSON #shell #CLI #BigQuery

[Upload JSON-file to GCP BigQuery] #GCP #Google #JSON #shell #CLI #BigQuery

# download a file to working directory
curl https://storage.googleapis.com/cloud-training/CPB200/BQ/lab4/schema_flight_performance.json -o schema_flight_performance.json

# Upload multiple JSON-files and create a table in BigQuery to a previously created dataSet
bq load --source_format=NEWLINE_DELIMITED_JSON $DEVSHELL_PROJECT_ID:cpb101_flight_data.flights_2014 gs://cloud-training/CPB200/BQ/lab4/domestic_2014_flights_*.json ./schema_flight_performance.json

# Check if table exists in dataset cpb101_flight_data
bq ls $DEVSHELL_PROJECT_ID:cpb101_flight_data

# Create environment variable for your BUCKET name
BUCKET = <insert name>
# Create BUCKET with this name in Console (Storage > Browser > Create Bucket)

# Export table via CLI
bq extract cpb101_flight_data.AIRPORTS gs://$BUCKET/bq/airports2.csv