1
如果項目不存在,我想將項目插入到Google數據存儲中。 我寫了一個數據流流作業。使用Google數據存儲以流模式檢查項目
工作
static class RawToObjectConverter extends DoFn<String, Entity> {
@Override
public void processElement(ProcessContext c) {
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()) {
Entity post = Entity.builder(datastore.newKeyFactory().newKey("Post"))
.set("postid", "1")
.set("title", "p1")
.build();
c.output(post);
}
}
}
問題
lines.apply(ParDo.of(new RawToObjectConverter()))
.apply(DatastoreIO.v1().write().withProjectId(projectid));
在類型PCollection<Entity>
方法apply(PTransform<? super PCollection<Entity>,OutputT>)
不適用的參數(DatastoreV1.Write
)
另外我應該使用com.google.cloud.datastore.Datastore
或com.google.datastore.v1.Entity
?
它給了我一個錯誤:「從類型BaseEntity的方法,鉛()是不可見的」 –
@KassemShehady看起來是不是一個公共方法。如果有其他選擇,請與數據存儲小組一起檢查。暫時您可以自己編寫此方法,https://github.com/GoogleCloudPlatform/google-cloud-java/blob/master/google-cloud-datastore/src/main/java/com/google/cloud/datastore /BaseEntity.java#L680 –