我正在尝试使用DatastoreIO.v1()。write()将不同种类的实体写入数据存储区。
在我的转换函数UpsertStoreItemEntityFn extends DoFn<String, Entity
中,我正在创建&#39; Entity
&#39;对象有条件地如下:
@Override
public void processElement(ProcessContext processContext) throws Exception {
IngestionJobRecord jobRecord = convertIntoIngestionJobRecord(processContext.element());
String validRecordMsg = isRecordValid(jobRecord);
if (validRecordMsg.isEmpty()) {
processContext.output(makeSuccessRecordEntity(jobRecord));
} else {
processContext.output(makeErrorRecordEntity(validRecordMsg, jobRecord));
}
}
private Entity makeErrorRecordEntity(String errorMessage, IngestionJobRecord jobRecord) {
Entity.Builder entityBuilder = Entity.newBuilder();
// All created entities have the same ancestor Key.
Key.Builder keyBuilder = makeKey("MyService.ErrorRecordEntity", UUID.randomUUID().toString());
keyBuilder.getPartitionIdBuilder().setNamespaceId(tenantId);
entityBuilder.setKey(keyBuilder.build());
..
..
}
private Entity makeSuccessRecordEntity(StoreItemEntity storeItemEntity) {
Entity.Builder entityBuilder = Entity.newBuilder();
// All created entities have the same ancestor Key.
Key.Builder keyBuilder = makeKey("MyService.SuccessRecordEntity", UUID.randomUUID().toString());
keyBuilder.getPartitionIdBuilder().setNamespaceId(tenantId);
entityBuilder.setKey(keyBuilder.build());
..
..
}
正如你所看到的,我正在设置不同的&#39; kind&#39;对于两个实体。问题是当管道中的这一行:
.apply(DatastoreIO.v1().write().withProjectId("myProject"));
执行,然后只将其中一种类型的实体写入数据存储区。
我想知道我做错了什么,或者这是DatastoreIO的限制,它不允许允许不同类型的实体一起写入。
如果无法做到这一点,我是否可以通过其他方式在数据流中的一个步骤中将两种实体类型写入数据存储区?
任何指针都非常赞赏!
由于 阿布舍克巴克