首页 > 解决方案 > 是否可以有效地将 PCollection 列表转换为 PCollection(只是列表中的值)?

问题描述

我知道可以使用 ParDo 函数直接从列表中生成元素,但是还有其他直接或更有效的方法吗?

标签: pythonmapreduceapache-beam

解决方案


按照官方文档,您可以使用该Flatten方法来合并 PCollections。Beam Programming Guide中提供了示例。

# Flatten takes a tuple of PCollection objects.
# Returns a single PCollection that contains all of the elements in the PCollection objects in that tuple.

merged = (
    (pcoll1, pcoll2, pcoll3)
    # A list of tuples can be "piped" directly into a Flatten transform.
    | beam.Flatten())

推荐阅读