如何从 Google 云存储 CSV 中读取并将其加载到 Google 数据存储

How to read from Google Cloud Storage CSV and Load it to Google Data Store

能否告诉我如何从 Google 存储 (CSV) 文件读取到 Cloud Data Store。

我已经完成了,Java 通过 App Engine 编写代码并且能够在调用时加载一行。同样,我想获得一些示例代码以一次性将批量(从 CSV 读取)加载到数据存储。

Can you please let me know how to read from Google Storage (CSV) file to Cloud Data Store.

您可以使用两种不同的解决方法从 Google 云存储中读取数据并加载到您的云数据存储项目中。

使用 Apache Beam

如此类似 中所述,您可以使用 Apache Beam 使用 TextIO class.

读取 CSV 文件

接下来,您需要应用一个转换来解析 CSV 文件中的每一行和 return 一个 Entity 对象。

在 post 中,您将找到有关如何基于 CSV 文件构造 Entity 对象的示例。

最后,将实体对象写入云数据存储。

使用数据流

您可以使用 Dataflow。 Google 提供了一组开源数据流模板,您可以使用它们来实现您正在寻找的目标。

就模板而言,您可以使用 Cloud Storage Text to Datastore.

The Cloud Storage Text to Datastore template is a batch pipeline which reads from text files stored in Cloud Storage and writes JSON encoded Entities to Datastore. Each line in the input text files should be in JSON format specified in https://cloud.google.com/datastore/docs/reference/rest/v1/Entity .

我强烈建议使用第一个选项,因为它看起来不错并且已获得批准。

如果它不起作用,您可以随时尝试使用 Dataflow 模板从 Google Cloud Storage 读取到 Cloud Datastore。

希望对您有所帮助。