1.前期数据准备(同之前的章节)

val collegesRdd= sc.textFile("/user/hdfs/CollegeNavigator.csv")
val header= collegesRdd.first

val headerlessRdd= collegesRdd.filter( line=>{ line!= header } )

2.获得map

val typeMapCount= headerlessRdd.map(line=>{
val strtype=line.split("\",\"")(3)
val strCount=line.split("\",\"")(7)
val stuCount=if (strCount.length()>0) strCount.toLong
else 0
(strtype,stuCount)
})
typeMapCount.take(10).foreach(println)

3使用reducebykey 方法

val typeReduce=typeMapCount.reduceByKey((sum,current)=>{
sum+current
})

4.数据排序

由于只有sortByKey这个方法,所以想按照后面的数据来排序,比较麻烦,必须把key value做两次置换,如下:

val typeReduce=typeMapCount.reduceByKey((sum,current)=>{
sum+current
}).map(line=>(line._2,line._1)).sortByKey().map(line=>(line._2,line._1))

typeReduce.take(10).foreach(println)

最新文章

  1. javascript undefined 和void0
  2. 增加eclipse启动的Tomcat内存的
  3. VBA访问SQLSERVER2005筛选数据库
  4. 人生规划和GTD——“知”、“得”与“合”
  5. SGU 149. Computer Network
  6. 浅谈Log4j
  7. PHP大批量插入mysql数据库的优化
  8. JDBC(三)数据库连接池(DBCP、C3P0)
  9. Re.多项式除法/取模
  10. expdp之include参数——实现表级别的expdp操作
  11. Mysql 允许远程连接
  12. Redis的数据结构之哈希
  13. Spring 3.1新特性之二:@Enable*注解的源码,spring源码分析之定时任务Scheduled注解
  14. EayRadius 于 2013-7-19 进行体验度更新,增加用户体验度
  15. 一个很棒的Flutter学习资源列表
  16. iPhone设备及屏幕适配
  17. Linux 复制、移动覆盖文件不提示
  18. verilog中的有符号数理解(转)
  19. 【我的Android进阶之旅】 Android Studio插件之Jenkins插件介绍
  20. POJ - 3268 Silver Cow Party SPFA+SLF优化 单源起点终点最短路

热门文章

  1. Gym - 100783G:Playing With Geometry (几何 离散化 )
  2. git 在某个分支下创建新分支
  3. CCF-Markdown-201703-3
  4. LCA - Tarjan 算法
  5. PTA——洗牌
  6. Synchronized 有几种用法?
  7. go环境变量与sublime Text3开发工具
  8. 从Firebird2.5 迁移到 Firebird3.0 手记
  9. 将string转为同名类名,方法名。(c#反射)
  10. 部署MySQL自动化运维工具inception+archer