由于您正在寻找一种将HTTP 请求流式传输到 BigQuery并批量发送它们以最小化 Google Cloud Platform 成本的方法,因此您可能需要查看解释此问题的公共文档。您还可以找到有关如何将流插入 BigQuery的 Node.js模板:
// Imports the Google Cloud client library
const {BigQuery} = require('@google-cloud/bigquery');
/**
* TODO(developer): Uncomment the following lines before running the sample.
*/
// const projectId = "your-project-id";
// const datasetId = "my_dataset";
// const tableId = "my_table";
// const rows = [{name: "Tom", age: 30}, {name: "Jane", age: 32}];
// Creates a client
const bigquery = new BigQuery({
projectId: projectId,
});
// Inserts data into a table
await bigquery
.dataset(datasetId)
.table(tableId)
.insert(rows);
console.log(`Inserted ${rows.length} rows`);
至于批处理部分,建议的比例是每个请求使用 500 行,即使它可以达到 10,000。有关流式插入的配额和限制的更多信息可以在公共文档中找到。