I am trying to save to Google Datastore from Google Dataflow Job it gives me this error
我正在尝试从Google Dataflow Job保存到Google Datastore,它给了我这个错误
My Code inside the DoFN is
我在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());
}
The error is :
错误是:
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
2 个解决方案
#1
#2
0
Faced the same issue and so thought the way out might help others too.
面对同样的问题,所以想出路也可以帮助别人。
I had google-cloud-datastore
(version 0.11.2-beta
) as my dependency which come up with datastore-v1-protos-1.0.1
. And I believe the root cause for the mentioned problem was this libs specific class com.google.datastore.v1.Entity.Builder
, which didn't support neither putProperties
nor getPropertiesMap
.
我有google-cloud-datastore(版本0.11.2-beta)作为我的依赖项,它提出了datastore-v1-protos-1.0.1。我相信上述问题的根本原因是这个libs特定的类com.google.datastore.v1.Entity.Builder,它既不支持putProperties也不支持getPropertiesMap。
Knowing the problem statement in a better way, helped me to sort the issue conventionally. I had to just make sure to get a new dependency of datastore-v1-protos
which supports those missing APIs. Hence just added below dependency in my pom.xml
以更好的方式了解问题陈述,帮助我按常规对问题进行排序。我必须确保获得支持那些缺少API的datastore-v1-protos的新依赖项。因此,在我的pom.xml中添加了以下依赖项
<dependency>
<groupId>com.google.cloud.datastore</groupId>
<artifactId>datastore-v1-protos</artifactId>
<version>1.3.0</version>
</dependency>
This change might create some protobuf regression, so include this dependency in your pom.xml
to avoid, if there is any such.
此更改可能会创建一些protobuf回归,因此请在pom.xml中包含此依赖项以避免(如果存在)。
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.2.0</version>
</dependency>
#1
1
Looks like toPb
is not a public method. Filed an issue here.
看起来toPb不是一个公共方法。这里提出了一个问题。
For the time being you could implement this method yourself.
暂时你可以自己实现这个方法。
#2
0
Faced the same issue and so thought the way out might help others too.
面对同样的问题,所以想出路也可以帮助别人。
I had google-cloud-datastore
(version 0.11.2-beta
) as my dependency which come up with datastore-v1-protos-1.0.1
. And I believe the root cause for the mentioned problem was this libs specific class com.google.datastore.v1.Entity.Builder
, which didn't support neither putProperties
nor getPropertiesMap
.
我有google-cloud-datastore(版本0.11.2-beta)作为我的依赖项,它提出了datastore-v1-protos-1.0.1。我相信上述问题的根本原因是这个libs特定的类com.google.datastore.v1.Entity.Builder,它既不支持putProperties也不支持getPropertiesMap。
Knowing the problem statement in a better way, helped me to sort the issue conventionally. I had to just make sure to get a new dependency of datastore-v1-protos
which supports those missing APIs. Hence just added below dependency in my pom.xml
以更好的方式了解问题陈述,帮助我按常规对问题进行排序。我必须确保获得支持那些缺少API的datastore-v1-protos的新依赖项。因此,在我的pom.xml中添加了以下依赖项
<dependency>
<groupId>com.google.cloud.datastore</groupId>
<artifactId>datastore-v1-protos</artifactId>
<version>1.3.0</version>
</dependency>
This change might create some protobuf regression, so include this dependency in your pom.xml
to avoid, if there is any such.
此更改可能会创建一些protobuf回归,因此请在pom.xml中包含此依赖项以避免(如果存在)。
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.2.0</version>
</dependency>