spark RDD,reduceByKey vs groupByKey
Spark 中有两个类似的api,分别是 reduceByKey 和 groupByKey 。这两个的功能类似,但底层实现却有些不同,那么为什么要这样设计呢?我们来从源码的角度分析一下。 先看两者的调用顺序(都是使用默认的Partitioner,即defaultPartitioner) 所用 spark 版本:spark 2.1.0 先看reduceByKey Step1 def reduceByKey(func: (V, V) => V): RDD[(K, V)] = self.withScope { reduceByKey(defaultPartitioner(self), func) } Setp2 def reduceByKey(partitioner: Partitioner, func: (V, V) => V): RDD[(K, V)] = self.withScope { combineByKeyWithClassTag[V]((v: V) => v, func, func, partitioner) } Setp3 def combineByKeyW...