5
我想了解在哪种情况下我应该使用FlatMap或Map。 The documentation对我来说似乎不太清楚。Apache Beam:FlatMap vs Map?
我仍然不明白在哪种情况下我应该使用FlatMap或Map的转换。
有人能给我一个例子,所以我可以理解他们的区别吗?
我明白FlatMap的VS地图Spark中的差异,但不知道是否有任何相似之处吗?
我想了解在哪种情况下我应该使用FlatMap或Map。 The documentation对我来说似乎不太清楚。Apache Beam:FlatMap vs Map?
我仍然不明白在哪种情况下我应该使用FlatMap或Map的转换。
有人能给我一个例子,所以我可以理解他们的区别吗?
我明白FlatMap的VS地图Spark中的差异,但不知道是否有任何相似之处吗?
Beam中的这些转换和Spark(斯卡拉)完全相同。
甲Map
变换,从N个元素的PCollection
映射成N个元件的另一PCollection
。
甲FlatMap
变换映射的N个元素到零个或多个元件,其然后压平成单个PCollection
N个集合的PCollections
。
一个简单的例子,发生以下情况:
beam.Create([1, 2, 3]) | beam.Map(lambda x: [x, 'any'])
# The result is a collection of THREE lists: [[1, 'any'], [2, 'any'], [3, 'any']]
鉴于:
beam.Create([1, 2, 3]) | beam.FlatMap(lambda x: [x, 'any'])
# The lists that are output by the lambda, are then flattened into a
# collection of SIX single elements: [1, 'any', 2, 'any', 3, 'any']
Pablo-明白了。感谢您的详细解释和示例。 :) – EmmaYang
您可以接受的答案,如果它是适当的:) – Pablo
优秀解释+1 – codebrotherone