MapReduce 编程 Wordcount很像 统计海选通票 每个选手得的票数 选秀全国各个地方的投票 写出map 和reduce函数
不会
package com.hpu.hadoop.mapreduce.wordcount;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import java.io.IOException;
public class WCMapper extends Mapper<LongWritable, Text,Text, IntWritable> {
private Text text;
private IntWritable intWritable;
// @Override
// protected void setup(Context context) throws IOException, InterruptedException {
// text = new Text();
// intWritable = new IntWritable(1);
// }
//
// @Override
// protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
// String line = value.toString();
//假设一行内容为多个姓名
// String[] words = line.split(" ");
// for (String word : words) {
// text.set(word);
// context.write(text,intWritable);
// }
// }
@Override
protected void setup(Context context) throws IOException, InterruptedException {
text = new Text();
intWritable = new IntWritable(1);
}
@Override
protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
String line = value.toString();
//假设一行内容为:姓名
text.set(line);
context.write(text,intWritable);
}
}
以上是两种不同数据格式的方案
这里的Reducer代码是WordCount中Reducer的代码一模一样