Wou*_*out 5 google-cloud-dataflow apache-beam
我在使用 DataflowRunner 创建 Map PCollectionView 时遇到问题。
下面的管道将 unbouded 计数输入与来自侧输入的值(包含 10 个生成的值)聚合在一起。在 gcp 上运行管道时,它会卡在 View.asMap() 转换中。更具体地说, ParDo(StreamingPCollectionViewWriter) 没有任何输出。
我用 dataflow 2.0.0-beta3 和 beam-0.7.0-SNAPSHOT 尝试了这个,但没有任何结果。请注意,使用本地 DirectRunner 时,我的管道运行没有任何问题。
难道我做错了什么?感谢所有帮助,在此先感谢您帮助我!
public class SimpleSideInputPipeline {
private static final Logger LOG = LoggerFactory.getLogger(SimpleSideInputPipeline.class);
public interface Options extends DataflowPipelineOptions {}
public static void main(String[] args) throws IOException {
Options options = PipelineOptionsFactory.fromArgs(args).withValidation().as(Options.class);
Pipeline pipeline = Pipeline.create(options);
final PCollectionView<Map<Integer, String>> sideInput = pipeline
.apply(CountingInput.forSubrange(0L, 10L))
.apply("Create KV<Integer, String>",ParDo.of(new DoFn<Long, KV<Integer, String>>() {
@ProcessElement
public void processElement(ProcessContext c) {
c.output(KV.of(c.element().intValue(), "TEST"));
}
}))
.apply(View.asMap());
pipeline
.apply(CountingInput.unbounded().withRate(1, Duration.standardSeconds(5)))
.apply("Aggregate with side-input",ParDo.of(new DoFn<Long, KV<Long, String>>() {
@ProcessElement
public void processElement(ProcessContext c) {
Map<Integer, String> map = c.sideInput(sideInput);
//get first segment from map
Object[] values = map.values().toArray();
String firstVal = (String) values[0];
LOG.info("Combined: K: "+ c.element() + " V: " + firstVal + " MapSize: " + map.size());
c.output(KV.of(c.element(), firstVal));
}
}).withSideInputs(sideInput));
pipeline.run();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1641 次 |
| 最近记录: |