google-app-engine – 从Google Dataflow保存到Google Datastore

我正在尝试从Google Dataflow Job保存到Google Datastore,它给了我这个错误

我在DoFN内的代码是

Datastore datastore= DatastoreOptions.getDefaultInstance().getService();
        TrackingRequest rq = gson.fromJson(c.element().toString(), TrackingRequest.class);
        Query<Entity> query = Query.entityQueryBuilder().kind("Post").filter(PropertyFilter.eq("postid", rq.postid))
                .build();
        QueryResults<Entity> posts = datastore.run(query);

        if (posts == null || !posts.hasNext()) {
            KeyFactory keyFactory = datastore.newKeyFactory().setKind("Post");
            Key key = keyFactory.newKey(rq.postid);

            Entity entity = Entity.newBuilder(key)
                    .set("appid", rq.appid)
                    .set("postid", rq.postid)
                    .set("title", rq.title)                 
                    .build();               


            datastore.put(entity);
            // c.output(((FullEntity<IncompleteKey>)entity).toPb());
        }

错误是:

exception: "java.lang.NoSuchMethodError: com.google.datastore.v1.Entity$Builder.putProperties(Ljava/lang/String;Lcom/google/datastore/v1/Value;)Lcom/google/datastore/v1/Entity$Builder;
at com.google.cloud.datastore.BaseEntity.toPb(BaseEntity.java:683)
at com.google.cloud.datastore.DatastoreImpl.put(DatastoreImpl.java:337)
at com.google.cloud.datastore.DatastoreHelper.put(DatastoreHelper.java:55)
at com.google.cloud.datastore.DatastoreImpl.put(DatastoreImpl.java:315)
at com.kryptonz.proccess.KryptonzArchive$RawToObjectConverter.processElement(KryptonzArchive.java:80)
at com.google.cloud.dataflow.sdk.util.SimpleDoFnRunner.invokeProcessElement(SimpleDoFnRunner.java:49)
at 

最佳答案 看起来像toPb不是一个公共方法.提起问题
here.

暂时你可以自己实现这个method.

点赞