MapReduce学生成绩(一)
MapReduce学生成绩(一)
小贾嗯嗯1 | computer,huangxiaoming,85 |
以上所有的是数据,该数据每行有三个字段值,分别是course,name,score
现在求:需求1:每一个course的最高分,最低分,平均分
返回结果格式:
course 95 22 55
例子:
computer 99 48 75
解题思路:
对于要求每门课程的最高分,最低分,平均分,这其实就是简单的按照课程分组,然后对分数做max,min,avg的聚合操作。
对于需求来说,并不复杂
对于mapper阶段,输出的key-value分别是:
key: 课程 course
value: 分数 score
对于reducer阶段,reduce方法接收的参数是:
key: 课程 course
values: 某一门课程对应的所有的score的一个迭代器
对于任何一个MapReduce程序来说,清楚的知道mapper阶段和reducer阶段的输入和输出是什么,这是写出mapreduce程序的关键
具体看代码实现:
1 | package com.xiaojia.stu; |
1 | package com.xiaojia.stu; |
1 | package com.xiaojia.stu; |
最后的执行结果:
1 | algorithm 85 42 74 |
评论
匿名评论隐私政策