我正在尝试从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

10-02 07:21