简体   繁体   English

在 BigQuery 中从具有多个表的数据生成 CSV 文件

[英]Generate a CSV file from data with multiple tables in BigQuery

We need to generate a CSV file from data which resides in multiple tables in BigQuery.我们需要从位于 BigQuery 中多个表中的数据生成一个 CSV 文件。

Currently we are trying to build a java service which will fetch data in TableResult with help of google-cloud-bigquery package and collecting data in TableResult object and looping through it to create a CSV.目前,我们正在尝试构建一个 java 服务,它将在 google-cloud-bigquery 包的帮助下获取 TableResult 中的数据,并在 TableResult 对象中收集数据并通过它循环创建一个 CSV。 How fast and scalable this method is.这种方法的速度和可扩展性如何。

Or do we have any other option provided by GCP to accomplish this task.或者我们是否有 GCP 提供的任何其他选项来完成此任务。 Please suggest.请建议。

The most efficient way to do so, is using build-in BigQuery export to GCS mechanism, because BigQuery uses its parallelism to write the output using multiple threads.最有效的方法是使用内置的BigQuery 导出到 GCS 机制,因为 BigQuery 使用其并行性来使用多个线程写入输出。 You can export up to 1 GB of table data to a single file.您最多可以将 1 GB 的表数据导出到单个文件。 If you are exporting more than 1 GB of data, use a wildcard to export the data into multiple files:如果您要导出超过 1 GB 的数据,请使用通配符将数据导出到多个文件中:

gs://<BUCKET_NAME>/csvfilename*.csv

Then, when all your .csv files are in Storage bucket, you can use gsutil compose command, which creates a new object whose content is the concatenation of a given sequence of source objects under the same bucket:然后,当所有.csv文件都在 Storage 存储桶中时,您可以使用gsutil compose命令,该命令创建一个新对象,其内容是同一存储桶下给定的源对象序列的串联:

gsutil compose gs://<BUCKET_NAME>/a.csv gs://<BUCKET_NAME>/b.csv gs://<BUCKET_NAME>/composite.csv

where composite.csv is a concatenation of a.csv and b.csv .其中composite.csva.csvb.csv的串联。 Please, refer to the documentation .请参阅 文档

I hope it helps.我希望它有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM