如何触发从 Cloud Storage 到 BigQuery 的数据从 Kubernetes Engine 上传?

stkvtflw

一个 api 服务器正在 Kubernetes Engine (GKE) 上运行。用户可以将相对较小的数据集(~100mb,具有相同数据结构的多个 .csv)从客户端应用程序上传到 Cloud Storage (GCS)。上传完成后,我需要将所有新 .csv 文件中的所有数据导入单个现有 BigQuery 表,其中包含一些特定于用户的参数(用用户 id 标记每一行可能是这样)。顺序无所谓。

Google 文档为此提供了基于 GUI 的解决方案和命令行解决方案。不过,我假设有一种方法可以从基于 GKE 的服务器本身触发上传并跟踪它的进度。我怎么做?

不确定这是否重要:GKE api 服务器是在 NodeJS 上编写的。

埃利奥特·布罗萨德

以下是将文件上传到 GCS 的示例,摘自BigQuery 文档您可以根据需要配置作业;该页面上有一些参考资料,以及带有附加功能的 GitHub 存储库链接

// 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 文件并将结果附加到所需的目标表。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

自动将数据上传到 Google Cloud Storage 和 BigQuery

如何使用 Cloud Scheduler 将数据存储到 Cloud Storage?

R到BigQuery数据上传错误

Google Cloud Storage上传会触发Firebase Cloud功能吗?

如何在已部署到Google Container Engine的容器中使用Google Cloud Storage?

Firebase Admin SDK 上传文件到 Google Cloud Storage

无法上传>〜2GB到Google Cloud Storage

通过 macOS 终端上传图片到 Google Cloud Storage

您如何使用Google-cloud / storage中的签名策略上传数据?

直接上传到BigQuery比上传到Cloud Storage快吗?

如何将上传到Firebase Cloud Storage的图像的公共URL上传到实时数据库

从BigQuery向Dataflow中的Cloud Storage写入数据时如何设置文件大小而不是分片数

如何通过Cloud Functions将文件上传到Cloud Storage并使用Firestore控制对Cloud Storage的访问?

如何将 Django PostgreSQL 数据库部署到 Google Cloud SQL (App Engine)

使用Google App Engine(Python)将文件上传到Google Cloud Storage

使用Google App Engine将大文件上传到Google Cloud Storage

如何将spring cloud任务java jar注册到spring数据流kubernetes中

如何在Google Cloud Storage中上传批处理对象?

如何在Google Compute Engine上验证到BigQuery?

如何从我的 Cloud Storage 存储分区自动创建 BigQuery 表?

无法使用默认服务帐户和Google云库从Google Kubernetes Engine访问Google Cloud Storage

使用Cloud Function将数据从Cloud Storage加载到BigQuery中(功能的替代方法?)

如何从Google App Engine读取Google Cloud Storage文件

如何使用Google Cloud Storage JSON API获取可恢复上传的上传进度信息?

将BigQuery表的并发导出扩展到Google Cloud Storage

从python后端到Google Cloud Storage中文件的公共URL(Google App Engine)

使用Java通过Google App Engine将文件上传到Google Cloud Storage :(无此类文件或目录)

是否可以将docker hub公共托管映像部署到Kubernetes Container Engine而不将其上传到Containers Registery?

将数据流传输到Bigquery与将数据上传到PubSub,然后使用数据流将数据插入到Bigquery之间的优缺点是什么