【问题标题】:How to combine .csv files in several shards in Google Cloud bucket?如何在 Google Cloud 存储桶中的多个分片中合并 .csv 文件?
【发布时间】:2020-04-11 16:15:48
【问题描述】:

我已将一个可用作公共 Google 存储桶的公共数据集移动到我自己的桶中。文件大小约为 10 GB。当数据移动时,文件被分成大约 47 个碎片,全部压缩。我无法将它们合并到一个文件中。我该如何组合它们?

以下链接提供的信息没有多大帮助:

https://cloud.google.com/storage/docs/gsutil/commands/compose

我的存储桶如下所示:

任何帮助将不胜感激。

【问题讨论】:

  • 每个文件部分的格式是什么?你说它们是压缩的……这是单独压缩的,还是如果所有部分都连接在一起,那么它是一个压缩文件吗?
  • 您将哪些公共数据集迁移到 Google Cloud Storage?用于移动文件的确切命令是什么?
  • 未压缩的大小是多少?什么是未压缩的格式?它是一种可附加的格式吗?
  • @Kolban:它们是 CSV 格式的。它们在从 nyc 公共存储桶中提取时被压缩。
  • @DanielOcando:这是 NYC 311 公共数据集 console.cloud.google.com/…>

标签: google-cloud-platform google-cloud-storage sharding


【解决方案1】:

使用 nodejs 组合

const { Storage } = require('@google-cloud/storage');
await storage.bucket(bucketName).combine(sourceFilenameList, destFilename)

【讨论】:

    【解决方案2】:

    我建议您使用Cloud Build。这不是最明显的解决方案,但它是无服务器且便宜的。非常适合您的 1 次用例。这是我建议执行的操作

    steps:
    - name: 'gcr.io/cloud-builders/gsutil'
      entrypoint: "bash"
      args: 
        - -c
        - |
           # copy all your files locally
           gsutil -m cp gs://311_nyc/311* .
    
           # Uncompress your file
           # I don't know your compression method? gunzip?
    
           # append your file in a merged file. Delete the files after the merge.
           for file in $(ls -1 311* ); do cat $file >> merged; rm $file; done
    
           # Copy the file to the destination bucket
           gsutil cp merged gs://myDestinationBucket/myName.csv
    
    options:
    # Use 1Tb of disk for getting all the files in the same time on the same server. 
    # I didn't understand is the 10Gb is per uncompressed file or the total size. 
    # If it's the total file size, I think that this option is useless
     diskSizeGb: 1000
    
    # Optionally extend the default 10 minutes timeout if it takes too much time.
     timeout: 660s
    

    【讨论】:

    • 谢谢@guillaume blaquire。我会试试这个。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-03
    • 2021-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-04
    • 2020-01-13
    相关资源
    最近更新 更多