次に、BigQuery documentationから取得したファイルをGCSにアップロードする例を示します。必要に応じてジョブを構成できます。そのページ上のいくつかの参照と追加機能を持つlink to the GitHub repoがあります:アップロードした後
// Imports the Google Cloud client libraries
const BigQuery = require('@google-cloud/bigquery');
const Storage = require('@google-cloud/storage');
// The project ID to use, e.g. "your-project-id"
// const projectId = "your-project-id";
// The ID of the dataset of the table into which data should be imported, e.g. "my_dataset"
// const datasetId = "my_dataset";
// The ID of the table into which data should be imported, e.g. "my_table"
// const tableId = "my_table";
// The name of the Google Cloud Storage bucket where the file is located, e.g. "my-bucket"
// const bucketName = "my-bucket";
// The name of the file from which data should be imported, e.g. "file.csv"
// const filename = "file.csv";
// Instantiates clients
const bigquery = BigQuery({
projectId: projectId
});
const storage = Storage({
projectId: projectId
});
let job;
// Imports data from a Google Cloud Storage file into the table
bigquery
.dataset(datasetId)
.table(tableId)
.import(storage.bucket(bucketName).file(filename))
.then((results) => {
job = results[0];
console.log(`Job ${job.id} started.`);
// Wait for the job to finish
return job.promise();
})
.then((results) => {
// Get the job's status
return job.getMetadata();
}).then((metadata) => {
// Check the job's status for errors
const errors = metadata[0].status.errors;
if (errors && errors.length > 0) {
throw errors;
}
}).then(() => {
console.log(`Job ${job.id} completed.`);
})
.catch((err) => {
console.error('ERROR:', err);
});
は、することができます新たにアップロードされたCSVファイル(複数可)を照会し、所望の目的地表に結果を追加しrun a query。
CSVファイルを(BigQueryクエリジョブの一部として)フェデレーションテーブルとして定義してから、 'SELECT *、 FROM MyCsvTable;のようなクエリを実行できますか?クエリジョブの一部として既存のテーブルに追加するように指定することができます。 –
@ElliottBrossard "BigQueryにアップロードせずにCSVからのクエリ"を意味しますか?アップロード後にBigQuery自体でこのデータを処理するよりも、これはずっと効率が悪くなると思います。 – stkvtflw
モデルによって異なります。一度に多くの100MBファイルを処理したい場合は、最初にBigQueryにCSVファイルを読み込む方が良い方法です。 「リアルタイム」ソリューションでは、フェデレーテッド・テーブルを使用できます。いずれにせよ、NodeJSのBigQuery APIを使用しようとしましたか?それはあなたが使用する必要があるように聞こえる。 –