【发布时间】:2016-03-14 04:13:44
【问题描述】:
作为以下问答的后续问题:
https://stackoverflow.com/questions/31156774/about-key-grouping-with-groupbykey
我想与谷歌数据流工程团队 (@jkff) 确认 Eugene 提出的第三个选项是否完全适用于谷歌数据流:
“有一个 ParDo 接受这些键并创建 BigQuery 表,另一个 ParDo 接受数据并将数据流写入表”
我的理解是 ParDo/DoFn 会处理每个元素,当从 ParDo/DoFn 的 processElement 写出时,我们如何指定表名(从侧面输入传入的键的功能)?
谢谢。
已更新,带有 DoFn,由于 c.element().value 不是 pcollection,因此显然无法正常工作。
PCollection<KV<String, Iterable<String>>> output = ...;
public class DynamicOutput2Fn extends DoFn<KV<String, Iterable<String>>, Integer> {
private final PCollectionView<List<String>> keysAsSideinputs;
public DynamicOutput2Fn(PCollectionView<List<String>> keysAsSideinputs) {
this.keysAsSideinputs = keysAsSideinputs;
}
@Override
public void processElement(ProcessContext c) {
List<String> keys = c.sideInput(keysAsSideinputs);
String key = c.element().getKey();
//the below is not working!!! How could we write the value out to a sink, be it gcs file or bq table???
c.element().getValue().apply(Pardo.of(new FormatLineFn()))
.apply(TextIO.Write.to(key));
c.output(1);
}
}
【问题讨论】:
-
现在可以在开箱即用的最新 Beam stackoverflow.com/questions/43505534/… 中使用