-
map:用于遍历RDD,将函数f应用于每一个元素,返回新的RDD(transformation算子)。
-
foreach:用于遍历RDD,将函数f应用于每一个元素,无返回值(action算子)。
-
mapPartitions:用于遍历操作RDD中的每一个分区,返回生成一个新的RDD(transformation算子)。
-
foreachPartition: 用于遍历操作RDD中的每一个分区。无返回值(action算子)。
-
总结:一般使用mapPartitions或者foreachPartition算子比map和foreach更加高效,推荐使用。
spark中的常用算子区别(map、mapPartitions、foreach、foreachPartition)
猜你喜欢
转载自blog.csdn.net/Sunshine_2211468152/article/details/83049974
今日推荐
周排行