如何在 dataflow/beam 中将 PCollection<List<String>> 转换为 PCollection<String>
How to convert PCollection<List<String>> to PCollection<String> in dataflow/beam
我有一个用例,我需要从 DoFn 输出多个 T
。所以 DoFn
函数是 returning 一个 PCollection<List<T>>
。我想将它转换为 PCollection<T>
以便稍后在管道中我可以像这样过滤:
PCollection<T> filteredT = filterationResult.apply(Filter.byPredicate(p -> p.equals(T) == T));
目前我能想到的最好的方法是,从 ParDo
函数中 returning List<T>
我 return KV<String,List<T>>
使用相同的键每一项。然后在管道中我可以做下面的合并结果:
filterationResult.apply("Group", GroupByKey.<String, List<T>>create())
或者我可以多次从 DoFn 调用 c.output(T)
(其中 c
是传入的 ProcessContext
对象)吗?
您可以多次从 DoFn
调用 c.output(T)
。
还有一个库转换 Flatten.iterables()
但在这种情况下您不需要它。
我有一个用例,我需要从 DoFn 输出多个 T
。所以 DoFn
函数是 returning 一个 PCollection<List<T>>
。我想将它转换为 PCollection<T>
以便稍后在管道中我可以像这样过滤:
PCollection<T> filteredT = filterationResult.apply(Filter.byPredicate(p -> p.equals(T) == T));
目前我能想到的最好的方法是,从 ParDo
函数中 returning List<T>
我 return KV<String,List<T>>
使用相同的键每一项。然后在管道中我可以做下面的合并结果:
filterationResult.apply("Group", GroupByKey.<String, List<T>>create())
或者我可以多次从 DoFn 调用 c.output(T)
(其中 c
是传入的 ProcessContext
对象)吗?
您可以多次从 DoFn
调用 c.output(T)
。
还有一个库转换 Flatten.iterables()
但在这种情况下您不需要它。