Apache Beam : FlatMap vs Map?

后端 未结 3 551
渐次进展
渐次进展 2020-12-14 07:35

I want to understand in which scenario that I should use FlatMap or Map. The documentation did not seem clear to me.

I still do not understand in which scenario I sh

3条回答
  •  再見小時候
    2020-12-14 08:23

    In simplest word,

    Map transformation is "one to one" mapping on each element of list/collection. Ex -

    {"Amar", "Akabar", "Anthony"} -> {"Mr.Amar", "Mr.Akabar", "Mr.Anthony"}
    

    FlatMap transformation is usually on collection like "list of list", and this collection gets flattened to single list and transformation/mapping is applied on each element of "list of list"/collection.

    FlatMap transformation Ex -

    { {"Amar", "Akabar"},  "Anthony"} -> {"Mr.Amar", "Mr.Akabar", "Mr.Anthony"}
    

    This concept remains same across programming language and across platform.

    Hope it helps.

提交回复
热议问题