Google bigquery 如何从Kubernetes引擎触发从云存储到BigQuery的数据上传?
一个api服务器正在Kubernetes引擎(GKE)上运行。用户可以将相对较小的数据集(约100mb,多个具有相同数据结构的.csv)从客户端应用程序上载到云存储(GCS)。上传完成后,我需要将所有新的.csv文件中的所有数据导入到一个现有的BigQuery表中,其中包含一些特定于用户的参数(用用户id标记每一行可能是左右)。秩序不重要 谷歌文档为此提供了基于GUI的解决方案和命令行解决方案。尽管如此,我认为有一种方法可以从基于GKE的服务器本身触发上传并跟踪其进度。我该怎么做Google bigquery 如何从Kubernetes引擎触发从云存储到BigQuery的数据上传?,google-bigquery,google-cloud-platform,Google Bigquery,Google Cloud Platform,一个api服务器正在Kubernetes引擎(GKE)上运行。用户可以将相对较小的数据集(约100mb,多个具有相同数据结构的.csv)从客户端应用程序上载到云存储(GCS)。上传完成后,我需要将所有新的.csv文件中的所有数据导入到一个现有的BigQuery表中,其中包含一些特定于用户的参数(用用户id标记每一行可能是左右)。秩序不重要 谷歌文档为此提供了基于GUI的解决方案和命令行解决方案。尽管如此,我认为有一种方法可以从基于GKE的服务器本身触发上传并跟踪其进度。我该怎么做 不确定这是否重
不确定这是否重要:GKE api服务器是在NodeJS上编写的。下面是一个将文件上载到GCS的示例,摘自。您可以根据需要配置作业;该页面上有一些参考资料和一个具有附加功能的:
// 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文件并将结果附加到所需的目标表。您可以将CSV文件定义为联合表(作为BigQuery查询作业的一部分),然后从MyCsvTable运行类似于
SELECT*的查询代码>?您可以指定作为查询作业的一部分附加到现有表中。@Elliottbrosard您的意思是“从csv查询而不将其上载到BigQuery”?我认为这比上传后在BigQuery中处理这些数据效率要低得多。我想这取决于模型。如果您想一次处理多个100MB文件,那么我同意先将CSV文件加载到BigQuery是更好的选择。对于“实时”解决方案,可以使用联邦表。在任何情况下,您是否尝试过从NodeJS使用BigQueryAPI?听起来这正是您需要使用的。我在“来自NodeJS的BigQuery API”中没有找到解决方案这是文档中的代码示例: