Google bigquery 哪个Bigquery nodejs客户端api方法用于加载带有通配符的GCS文件
我正在尝试编写一个云函数,将匹配通配符的GCS文件加载到BigQuery中。我在api参考中看到的所有示例都是load方法,它通过bigquery.dataset.table.load方法指定了一个特定的文件名 我可以使用什么方法使用通配符触发文件加载?我知道我可以指定元数据源uri,但看不到加载方法示例。谢谢你的帮助 这是我的密码Google bigquery 哪个Bigquery nodejs客户端api方法用于加载带有通配符的GCS文件,google-bigquery,google-cloud-storage,google-api-nodejs-client,Google Bigquery,Google Cloud Storage,Google Api Nodejs Client,我正在尝试编写一个云函数,将匹配通配符的GCS文件加载到BigQuery中。我在api参考中看到的所有示例都是load方法,它通过bigquery.dataset.table.load方法指定了一个特定的文件名 我可以使用什么方法使用通配符触发文件加载?我知道我可以指定元数据源uri,但看不到加载方法示例。谢谢你的帮助 这是我的密码 exports.importReadyToIngestFiles = (event, context) => { const pubsubMessage
exports.importReadyToIngestFiles = (event, context) => {
const pubsubMessage = event.data;
console.log(Buffer.from(pubsubMessage, 'base64').toString());
const bucketName = Buffer.from(pubsubMessage, 'base64').toString();
const {BigQuery} = require('@google-cloud/bigquery');
const {Storage} = require('@google-cloud/storage');
//specify projectID and bigquery datasetID below
const projectId = "test-3";
const datasetId = "Data";
const filename = "p_*";
const gcsFile = `${bucketName}/p_*`;
const tableId = "numeric";
const bigquery = new BigQuery({
projectId: projectId,
});
const storage = new Storage({
projectId: projectId,
});
let job;
// Loads data from a Google Cloud Storage file into the table
bigquery
.dataset(datasetId)
.table(tableId)
.load(storage.bucket(bucketName).file(filename))
.then(results => {
job = results[0];
console.log(`Job ${job.id} started.`);
// Wait for the job to finish
return job;
})
.then(metadata => {
// Check the job's status for errors
const errors = metadata.status.errors;
if (errors && errors.length > 0) {
throw errors;
}
})
.then(() => {
console.log(`Job ${job.id} completed.`);
})
.catch(err => {
console.error('ERROR:', err);
});
// callback();
};
更新:啊,通过查看BigQuery作业历史记录错误,我发现我的文件是管道分隔的,所以列不匹配。现在,在哪里可以找到如何指定分隔符?是我还是nodejsbigqueryapi文档有点不清楚 正如您在初始问题中提到的,我假设有一个选项可以在参数内的load中提供sourceUris[]字段,以利用通配符搜索,这一点已经在文档中得到确认: sourceUris[] 指向Google云中数据的完全限定URI。对于 谷歌云存储URI:每个URI可以包含一个“*”通配符 字符,它必须位于“bucket”名称之后 将元数据指定为.load类的输入值,如下所示:
const metadata = {
sourceUris: [gs://my_bucket*],
...
};
bigquery
.load(metadata)
还可以为元数据采用fieldDelimiter字段,以便调整输入数据文件的列分隔符
您可能会找到createLoadJob类的源代码。是否尝试用通配符运算符(例如gs://my_bucket/*.csv)替换filename/string参数?是的。那没有收集到文件。我也没有出错。它应该可以工作。你确定问题不是别的吗?查看触发的实际BigQuery加载作业的日志,看看上面写着什么。@AIKDO您解决了什么问题?