【问题标题】:What is the right way to create Datastore Entity and use it in Dataflow pipeline创建数据存储实体并在数据流管道中使用它的正确方法是什么
【发布时间】:2016-10-11 19:06:49
【问题描述】:

以下哪一种是创建数据存储实体的正确/首选方式:

    // First, create a fake email for our fake user
    final String email = "me@fake.com";

    // Now, create a 'key' for that user using the email
    final Key userKey =
            datastore.newKeyFactory().kind("user").newKey(email);

    // Now create a entity using that key adn add some fields to it
    final Entity newUser =
            Entity
                    .builder(userKey)
                    .set("name", "Faker")
                    .set("email", email)
                    .build();

或者就像在 DatastoreWordCount example 中完成的一样?

  • 第一个示例中的实体是com.google.cloud.datastore.Entity
  • 第二个示例中的实体是com.google.datastore.v1.Entity

我有使用 com.google.cloud.datastore.Entity 的代码,但我不知道如何将它存储为 Datastore 管道的一部分,因为我在网上找到的所有代码示例都建议:

com.google.cloud.dataflow.sdk.io.datastore.DatastoreIO.v1().write()

但它只适用于com.google.datastore.v1.Entity

我正在使用com.google.cloud.dataflow:google-cloud-dataflow-java-sdk-all:1.7.0

【问题讨论】:

    标签: java google-cloud-datastore google-cloud-dataflow


    【解决方案1】:

    您已经很好地分析了情况 - Dataflow 的 DatastoreIO.v1()com.google.datastore.v1.Entity 配合使用。

    【讨论】:

    • 有什么方法可以在 Dataflow 中为实体创建默认密钥,就像我们可以在 Google Datastore 中为实体创建一样,而无需证明密钥的任何手动 ID 或名称。
    猜你喜欢
    • 1970-01-01
    • 2016-04-01
    • 1970-01-01
    • 2011-05-29
    • 1970-01-01
    • 2013-02-01
    • 1970-01-01
    • 2015-03-20
    • 1970-01-01
    相关资源
    最近更新 更多