通过 Google Java 的云客户端库将数据输出到带有实体的数据存储

Output data to Datastore with Entity by Google Cloud Client Library for Java

我的管道将数据存储到 Datastore。 当我使用 google api 服务创建实体对象时,没有任何编译错误。 如下页所示,我应该 Google Cloud Client Library 而不是 Google api 服务。 https://developers.google.com/api-client-library/java/apis/datastore/v1beta2

所以我更改了我的代码以使用 Google Cloud Client Library for Java。但是出现编译错误。

The method apply(PTransform,OutputT>) in the type PCollection is not applicable for the arguments (DatastoreV1.Write)

如何解决错误?

您应该使用 DatastoreIO,而不是 Google 数据存储云客户端库,除非您想要处理自己编写 PTransform 的开销。你能post代码或更多关于实现的细节吗?

根据文档here,您的代码应如下所示:

PCollection<Entity> entities = ...;
entities.apply(DatastoreIO.v1().write().withProjectId(projectId));

可以找到 DatastoreV1.Write 的文档 here。除非您了解大部分实施细节,否则我无法回答其他问题。我会 post 将此作为评论,但不幸的是没有足够的声誉。