hadoop----mapreduce的案例(一)(找最高分,平均分)

该博客介绍了如何使用Hadoop MapReduce解决实际问题,通过案例展示了如何找出每个学生的最高分和平均分。在最高分的计算中,详细解释了map、reduce函数及驱动类的实现。在平均分的计算部分,利用KeyValueTextInputFormat处理数据,同样展示了map、reduce函数的运用及其运行结果。

案例一

现有三个文件,分别放置五个学生三门学科成绩
如下图所示,需要通过mapreduce程序,找出每一个学生的最高分和平均分
在这里插入图片描述

最高分

map函数


public class MyMapper extends Mapper<LongWritable, Text, Text, IntWritable>{

	@Override
	protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, IntWritable>.Context context)
			throws IOException, InterruptedException {
		// TODO Auto-generated method stub
		StringTokenizer st = new StringTokenizer(value.toString());
		while(st.hasMoreTokens()){
			Text sid = new Text(st.nextToken());
			IntWritable score = new IntWritable(Integer.parseInt(st.nextToken()));
			context.write(sid, score);
		}
	}	
}

reduce函数

public class MyReducer extends Reducer<Text, IntWritable, Text, IntWritable>{

	@Override
	protected void reduce(Text key, Iterable<IntWritab
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值