groupByKey把相同的key的数据分组到一个集合序列当中:
[("hello",1), ("world",1), ("hello",1), ("fly",1), ("hello",1), ("world",1)] --> [("hello",(1,1,1)),("word",(1,1)),("fly",(1))]
reduceByKey把相同的key的数据聚合到一起并进行相应的计算:
[("hello",1), ("world",1), ("hello",1), ("fly",1), ("hello",1), ("world",1)] add--> [("hello",3),("word",2),("fly",1)]
sortByKey按key的大小排序,默认为升序排序:
[(3,"hello"),(2,"word"),(1,"fly")] --> [(1,"fly"),(2,"word"),(3,"hello")]
groupByKey对分组后的每个key的value做mapValues(len)后的结果与reduceByKey的结果一致,即:如果分组后要对每一个key所对应的值进行操作则应直接用reduceByKey;sortByKey是按key排序,如果要对value排序,可以交换key与value的位置,再排序。