我在尝试将数据存储备份加载到 BigQuery 中的现有表中时遇到问题。我收到以下错误:
类型错误:bigquery.dataset(...).table(...).load 不是函数
我正在遵循 BigQuery cloud Api 中的示例之一 repo 协议(protocol)。
不确定我是否使用了错误的方式,但我想要实现的只是让我的云函数从数据存储转储中更新此 BigQuery 表,而不是每天删除和创建 - 这似乎是相反的富有成效,我以前也在这样做。
这是我的代码:
exports.processFile = function (event, callback) {
const BigQuery = require('@google-cloud/bigquery');
const Storage = require('@google-cloud/storage');
const bucketName = 'nyt-links-backup-dev';
const filename = event.data.name;
const tableId = 'links_data_tbl';
const projectId = 'nyt-sartre-dev';
// Instantiates clients
const bigquery = new BigQuery({
projectId: projectId,
});
const storage = new Storage({
projectId: projectId,
});
const datasetId = 'sartre_sublink_dataset';
const dataset = bigquery.dataset(datasetId);
const metadata = {
sourceFormat: 'AVRO',
};
// Loads data from a Google Cloud Storage file into the table
bigquery
.dataset(datasetId)
.table(tableId)
.load(storage.bucket(bucketName).file(filename), metadata)
.then(results => {
const job = results[0];
// load() waits for the job to finish
assert.equal(job.status.state, 'DONE');
console.log(`Job ${job.id} completed.`);
// Check the job's status for errors
const errors = job.status.errors;
if (errors && errors.length > 0) {
throw errors;
}
})
.catch(err => {
console.error('ERROR:', err);
});
callback();
};
最佳答案
听起来您使用的 BigQuery 库版本在 Table
上没有 load
功能。 load
函数于 2017 年 12 月在 version 0.12.0 中引入。以前称为导入
。
关于javascript - 使用云函数将数据加载到 BigQuery 表中时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50374985/