Skip to content

Instantly share code, notes, and snippets.

@chipoglesby
Created March 4, 2016 16:23
Show Gist options
  • Select an option

  • Save chipoglesby/50c746a8dd01befbb69a to your computer and use it in GitHub Desktop.

Select an option

Save chipoglesby/50c746a8dd01befbb69a to your computer and use it in GitHub Desktop.
Use Google Apps Script to Create A BigQuery Table with nested JSON fields.
function createBigQueryTable() {
projectId = "xxx";
datasetId = "xxx";
var tableId = 'xxx';
var table = {
tableReference: {
projectId: projectId,
datasetId: datasetId,
tableId: tableId
},
schema: {
fields: [
// This example is for the Google Maps API. You can change the fields as needed, but this is used to demostrated nested fields.
{name: 'location', type: 'RECORD', "fields": [{name: 'lat', type: 'FLOAT'},{name: 'lng', type: 'FLOAT'}]},
{name: 'id', type: 'STRING'},
{name: 'place_id', type: 'STRING'},
{name: 'reference', type: 'STRING'}
]
}
};
table = BigQuery.Tables.insert(table, projectId, datasetId);
Logger.log('Table created: %s', table.id);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment