Apache Beam:平坦的PCollection< list< foo>>> pcollection< foo>
假设我们有一些嵌套列表:
["a", "b"]
["c", "d"]
我们可以像这样轻松地在流API中进行襟翼映射:
Stream
.of(List.of("a", "b"), List.of("c", "d"))
.flatMap(List::stream)
.forEach(System.out::println);
但是使用“ Flatmapelements”进行,这是一团糟:
Pipeline pipeline = Pipeline.create();
pipeline.apply(Create.of(List.of(List.of("a", "b"), List.of("c", "d"))))
.apply(FlatMapElements.into(TypeDescriptor.of(String.class)).via(list -> list))
.apply(ParDo.of(new SomeOutputFunction()));
我们可以使用平面地图功能做得更好吗?
简单的flatmap工作不应该那么复杂,所以我认为我缺少一些东西。
由于类型推理问题,我什至无法替换 .via(list - > list)
。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
“ .apply(flatten.iterables())”
它将转换“ pcollection< list>”到“ PCollection”
".apply(Flatten.iterables())"
it will convert "PCollection<List>" to "PCollection"
请参阅《 apache beam编程指南:
Please refer to the Apache Beam programming guide https://beam.apache.org/documentation/programming-guide/#flatten: