阅读背景:

MapReduce处理数据平均值与数值大小排行比较

来源:互联网 

一:盘算数据平均值

在map中将名称作为key 数据为value写出去

/*
 * 盘算平均成就
 * 名字作为key	分数值为value写出去
 */
public class AverageMap extends Mapper<LongWritable, Text, Text, IntWritable> {
	protected void map(
			LongWritable key,
			Text value,
			org.apache.hadoop.mapreduce.Mapper<LongWritable, Text, Text, IntWritable>.Context context)
			throws java.io.IOException, InterruptedException {
		String line = value.toString();
		if (line.trim().length() > 0) {
			String[] str = line.split("\t");
			if (str.length == 2) {
				context.write(new Text(str[0]),
						new IntWritable(Integer.valueOf(str[1])));
			}
		}

	};
}/*
 * 盘算平均成就




你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: