我有一个大表(超过50GB)。我将使用查询作业创建一个新表。
查询结果行不需要。我希望能够等到工作完全完成。
const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
async function run() {
const [job] = await bigquery.createQueryJob({
// Actually I'm going to use a complex query rather than a simple copy.
query: 'SELECT * FROM `myproject.mydataset.mytable',
destinationTable: {
...
}
});
// I want to wait until the destination table creation is completed.
// But getQueryResults() brings overflow.
const [result] = await job.getQueryResults();
// I'd like to do other things after the destination table is created.
...
}
run();
像上面的代码,我尝试使用getQueryResults,但它给JavaScript堆内存不足。
我也尝试使用{maxResult:1}选项getQueryResults()。但是它在目标表创建之前返回。
对于Node.js的BigQuery,是否有办法等到目标表创建完成?
也许job.on('complete', ...)
事件可以帮到你。参见:https://cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/job
你可以这样做:
const [job] = await bigquery.createQueryJob(...);
await new Promise((resolve, reject) =>
job
.on('complete', resolve)
.on('error', reject)
);
job.removeAllListeners();