Apache Beam:平坦的PCollection< list< foo>>> pcollection< foo>

发布于 2025-02-03 19:06:42 字数 736 浏览 3 评论 0 原文

假设我们有一些嵌套列表:

["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)

Say we have some nested list:

["a", "b"]
["c", "d"]

And we can easily do the flap map in Stream API like this:

Stream
        .of(List.of("a", "b"), List.of("c", "d"))
        .flatMap(List::stream)
        .forEach(System.out::println);

But doing it with "FlatMapElements", it was quite a mess:

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()));

Can we do anything else better with the flat map function?
A simple flatmap job should not be that complicated so I think I am missing something.
I cannot even replace .via(list -> list) to .via(Function.identity()) due to the type inference problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

迟月 2025-02-10 19:06:42

“ .apply(flatten.iterables())”
它将转换“ pcollection< list>”到“ PCollection”

".apply(Flatten.iterables())"
it will convert "PCollection<List>" to "PCollection"

烏雲後面有陽光 2025-02-10 19:06:42

请参阅《 apache beam编程指南

PCollectionList<String> collections = PCollectionList.of(pc1).and(pc2).and(pc3);

PCollection<String> merged = collections.apply(Flatten.<String>pCollections());

Please refer to the Apache Beam programming guide https://beam.apache.org/documentation/programming-guide/#flatten:

PCollectionList<String> collections = PCollectionList.of(pc1).and(pc2).and(pc3);

PCollection<String> merged = collections.apply(Flatten.<String>pCollections());
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文