MapReduce在集群中使用
上传数据
数据格式准备如下:
创建项目
https://blog.csdn.net/qq_45765882/article/details/103092093
我在这篇文章中详细了如何创建一个新的项目和POM文件的数据
定义mapper类
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import java.io.IOException;
public class WordCountMapper extends Mapper<LongWritable,Text,Text,LongWritable> {
@Override
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
String line = value.toString();
String[] split = line.split(",");
for (String word : split) {
context.write(new Text(word),new LongWritable(1));
}
}
}
定义reducer类
import org.apache.hadoop.io.LongWri