【发布时间】:2020-05-07 13:25:28
【问题描述】:
我有一段代码对我的数据进行分组,但在我输出时它会引发异常。
这个类作为KV中的key
class CKey {
private Long id;
private Long subId;
}
这是我的数据流工作的一部分
TupleTag<CItem> itemsTuple = //...
TupleTag<CMeta> metaTuple = //...
//...
PCollection<KV<CKey, CItem>> items = null;
PCollection<KV<CKey, CMeta>> meta;
KeyedPCollectionTuple.of(itemsTuple, items).and(metaTuple, meta.next())
.apply(CoGroupByKey.create())
.apply(new CustomGroupPairsFn());
加入数据的自定义函数
class CustomGroupPairsFn extends DoFn<KV<CKey, CoGbkResult>, MyCustomObject> {
@ProcessElement
public void processElement(@Element KV<CKey, CoGbkResult> element, OutputReceiver<MyCustomObject> out) {
CoGbkResult pair = element.getValue();
Iterator<CItem> citem = pair.getAll(ITEMS).iterator();
Iterator<CMeta> cmeta = pair.getAll(METADATA).iterator();
try {
out.output(new MyCustomObject(citem.next(), cmeta));
} catch (Exception e) {
log.error("Error occurred", e);
}
}
}
try里面只有1行代码,里面抛出异常,异常:
我该如何解决这个问题?
【问题讨论】:
-
您能详细介绍一下您的管道吗?附近有 GroupByKey 吗?是流媒体吗?还是批量?
标签: java google-cloud-platform google-cloud-dataflow apache-beam