问题描述
我正在尝试使用 Dataflow/Beam 上的 Python SDK 获取 PCollection
中项目的示例.
I'm trying to get a sample of the items in PCollection
using the Python SDK on Dataflow / Beam.
虽然没有记录,但 Sample.FixedSizeGlobally(n)
存在.
While it's not documented, Sample.FixedSizeGlobally(n)
exists.
在测试时,似乎返回一个带有单个项目的 PCollection
:一个包含样本的列表,而不是一个带有样品.那是对的吗?
When testing, it seems to return a PCollection
with a single item: a list containing the samples, rather than a PCollection
with the samples. Is that correct?
这样做是否是将单项 PCollection
变成项目的 PCollection
的最佳方式?
Is doing this the best way of turning that single-item PCollection
into a PCollection
of the items?
| Sample.FixedSizeGlobally(sample_size)
| beam.FlatMap(lambda x: x)
推荐答案
目前,是的.Sample.FixedSizeGlobally()
转换返回一个带有单个列表元素的 PCollection.您可以像您说的那样将其变成单个元素的 PCollection:
Currently, yes. The Sample.FixedSizeGlobally()
transform returns a PCollection with a single list element. You can turn it into a PCollection of single elements like you said:
Sample.FixedSizeGlobally(sample_size)
| beam.FlatMap(lambda x: x)
我们将确保添加 PC-PC 转换 - 我们也欢迎您对 Beam 做出贡献 :) - 但与此同时,这就是我们所拥有的.
We'll make sure to add a PC-PC transform - and we also welcome your contributions to Beam : ) - But in the meantime, that's what we've got.
这篇关于使用 Python 在 Dataflow/Beam 中的示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!