在使用Flatten进行多个Pcollection合并时,需确保Pcollection已经被赋值或含有数据。以下是示例代码:
import apache_beam as beam
with beam.Pipeline() as pipeline:
pcoll1 = pipeline | "Create Pcollection 1" >> beam.Create([1, 2, 3])
pcoll2 = pipeline | "Create Pcollection 2" >> beam.Create([4, 5, 6])
merged_pcoll = ((pcoll1, pcoll2) | "Flatten" >> beam.Flatten())
merged_pcoll | "Print Merged Pcollection" >> beam.Map(print)
在此示例中,我们创建了两个Pcollection,分别包含整数1到3和4到6。然后,我们使用Flatten将两个Pcollection合并成一个Pcollection。最后,我们使用Map函数打印出合并后的Pcollection。
需要注意的是,在Flatten函数之前,每个Pcollection都需要给予赋值或者含有数据。因为Flatten展开所有的输入pcollection ,从而使它们中的所有元素都变为对输出pcollection 的元素的数据点的多次引用。如果没有划分的数据或没有数据,则Flatten函数不会返回任何内容。
使用此代码示例可解决“Apache Beam Flatten is not taking data from others Pcollection”的问题。