赞
踩
scala> b.map((_,1)).reduceByKey(_+_).collect
res26: Array[(String, Int)] = Array((hive,1), (spark,3), (jeff,2), (ruoze,1), (hadoop,1), (hi,1))
现有这样的一个已经做好wordcount的RDD,对其进行排序
升序:
scala> b.map((_,1)).reduceByKey(_+_).sortBy(_._2).collect
res29: Array[(String, Int)] = Array((hive,1), (ruoze,1), (hadoop,1), (hi,1), (jeff,2), (spark,3))
降序:
scala> b.map((_,1)).reduceByKey(_+_).sortBy(_._2,false).collect
res30: Array[(String, Int)] = Array((spark,3), (jeff,2), (hive,1), (ruoze,1), (hadoop,1), (hi,1))
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。