【问题标题】:Importing a large CSV from Cloud Storage into App Engine Datastore将大型 CSV 从 Cloud Storage 导入 App Engine Datastore
【发布时间】:2015-09-06 02:24:31
【问题描述】:

我有一个大的 CSV 文件,大约 1 GB,并且想要在数据存储中创建实体,每行一个实体。

该 CSV 文件当前位于 Google Cloud Storage 中。有没有一种干净的方法可以做到这一点?我可以在网上找到的所有示例似乎都依赖于在本地保存 CSV 文件,或者看起来它们不能很好地扩展。理想情况下,有一个流式 API 可以让我从 Cloud Storage 读取足够小的片段,以便对 Datastore 进行更新调用,但我找不到类似的东西。

【问题讨论】:

    标签: python csv google-app-engine google-cloud-storage google-cloud-datastore


    【解决方案1】:

    【讨论】:

      【解决方案2】:

      打开 GCS 文件时收到的缓冲区是流式缓冲区,可以腌制。但是 GCS 不支持迭代器协议来读取 CSV 的行。你必须write your own wrapper。喜欢:

      with gcs.open('/app_default_bucket/csv/example.csv', 'r') as f:
              csv_reader = csv.reader(iter(f.readline, ''))
              for row in csv_reader:
                  logging.info(' - '.join(row))
      

      如果您熟悉 blobstore,则可以使用它使用 blobstore.create_gs_key( "/gs" + <gcs_file_name_here>) 从 GCS 读取大型 CSV。 示例here

      【讨论】:

        猜你喜欢
        • 2012-01-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-04-13
        • 2014-04-10
        • 1970-01-01
        • 2020-04-04
        相关资源
        最近更新 更多