【发布时间】:2022-08-16 06:35:21
【问题描述】:
我正在尝试将具有许多元素的PCollection 转换为具有一个元素的PCollection。基本上,我想从:
[1,2,3,4,5,6]
至:
[[1,2,3,4,5,6]]
这样我就可以在DoFn 中处理整个PCollection。
我试过CombineGlobally(lamdba x: x),但一次只有一部分元素组合成一个数组,结果如下:
[1,2,3,4,5,6] -> [[1,2],[3,4],[5,6]]
或者类似的东西。
这是我试图运行的脚本的相关部分:
import apache_beam as beam
raw_input = range(1024)
def run_test():
with TestPipeline() as test_pl:
input = test_pl | \"Create\" >> beam.Create(raw_input)
def combine(x):
print(x)
return x
(
input
| \"Global aggregation\" >> beam.CombineGlobally(combine)
)
pl.run()
run_test()
标签: apache-beam