groupByKey和reduceByKey
1.groupByKey是没有combine过程 combineByKeyWithClassTag[CompactBuffer[V]](createCombiner, mergeValue, mergeCombiners, partitioner, mapSideCombine = false) 2.reduceByKey有combine过程 combineByKeyWithClassTag[V]((v: V) => v, func, func, partitioner) //mapSideCombine默认是true 1、如果v是数字运算,如wordcount减少网络传输次数 2、如果v是List[],对v进行收集,因为只收集v所以可以节省空间
注意:reduceByKey不能改变 v 的返回值类型
两者都可重新指定分区
repartition 和 coalesce
rdd.repartition(n)调用的就是coalesce,始终进行shuffle操作。
如果是减少分区,推荐使用coalesce,可以指定是否进行shuffle操作,默认是false即不分区
通过coalesce增加分区时,必须指定shuffle为true,否则分区数不变。