私はcsvファイルからbigqueryにデータをロードするスタンドアロンスクリプトを作成しましたが、スプレッドシートをbigqueryに読み込む方法を知りたいと思います。ここでは、csvからbigqueryにデータをロードするための私のコードです。私はcsvファイルの代わりにGoogleスプレッドシートの変更を行う場所を知りたいと思います。googleスプレッドシートからbigqueryにデータを読み込むためのスタンドアロンスクリプト
function loadCsv() {
// Replace this value with the project ID listed in the Google
// Developers Console project.
var projectId = '775034665452';
var datasetId = 'DEV';
// Sample CSV file of Google Trends data conforming to the schema below.
// https://docs.google.com/file/d/0BwzA1Orbvy5WMXFLaTR1Z1p2UDg/edit
var csvFileId = '0BwzA1Orbvy5WMXFLaTR1Z1p2UDg';
// Create the table.
var tableId = 'pets_' + new Date().getTime();
var table = {
tableReference: {
projectId: projectId,
datasetId: datasetId,
tableId: tableId
},
schema: {
fields: [
{name: 'week', type: 'STRING'},
{name: 'cat', type: 'INTEGER'},
{name: 'dog', type: 'INTEGER'},
{name: 'bird', type: 'INTEGER'}
]
}
};
table = BigQuery.Tables.insert(table, projectId, datasetId);
Logger.log('Table created: %s', table.id);
// Load CSV data from Drive and convert to the correct format for upload.
var file = DriveApp.getFileById(csvFileId);
var data = file.getBlob().setContentType('application/octet-stream');
// Create the data upload job.
var job = {
configuration: {
load: {
destinationTable: {
projectId: projectId,
datasetId: datasetId,
tableId: tableId
},
skipLeadingRows: 1
}
}
};
job = BigQuery.Jobs.insert(job, projectId, data);
Logger.log('Load job started. Check on the status of it here: ' +
'https://bigquery.cloud.google.com/jobs/%s', projectId);
}
感謝を!!しかし、私たちはGCSまたは手動からそれをロードするのではなく、BigQueryのためにスプレッドシートからデータをロードするためのスクリプトを書くことができるかどうかを知りたいです。 – nikhil
はい、このドキュメントのメイトを確認してください:https://cloud.google.com/blog/big-data/2016/05/bigquery-integrates-with-google-drive –