6. RDD综合练习:更丰富的操作

集合运算练习

union(), intersection(),subtract(), cartesian()

image-20220420142403767

内连接与外连接

join(), leftOuterJoin(), rightOuterJoin(), fullOuterJoin()

多个考勤文件,签到日期汇总,出勤次数统计

image-20220420142740990

综合练习:学生课程分数

网盘下载sc.txt文件,通过RDD操作实现以下数据分析:

导入数据

image-20220420143409027

数据分析

  • 持久化 scm.cache()

image-20220420143524574

  • 总共有多少学生?map(), distinct(), count()

image-20220420144448163

  • 开设了多少门课程?

image-20220420144511694

  • 生成(姓名,课程分数)键值对RDD,观察keys(),values()

image-20220420144551682

  • 每个学生选修了多少门课?map(), countByKey()

image-20220420144621263

  • 每门课程有多少个学生选?map(), countByValue()

image-20220420144639914

  • 有多少个100分?

image-20220420144819874

  • Tom选修了几门课?每门课多少分?filter(), map() RDD

image-20220420145600952

  • Tom选修了几门课?每门课多少分?map(),lookup() list

image-20220420145628655

  • Tom的成绩按分数大小排序。filter(), map(), sortBy()

image-20220420145705707

  • 生成(姓名课程,分数)RDD,观察keys(),values()

image-20220420150834897

  • 每个分数+20平时分。
    分别用mapValues(func)和 map(func)实现。并查看不及格人数的变化。

​ mapValues(func)

image-20220420151212710

​ map(func)

image-20220420151346767

​ 查看不及格人数的变化

image-20220420151942386

  • 求每门课的选修人数及平均分

  • reduceByKey()和collectAsMap()实现

image-20220420152657165

  • combineByKey(),map(),round()实现,确到2位小数

    combineByKey()实现

image-20220420152132577

​ map(),round()实现

image-20220420152401921

posted @ 2022-04-20 17:31  川久保玲球  阅读(10)  评论(0编辑  收藏  举报