原始数据
HDFS
words
hello tom
hello jerry
hello kitty
hello world
hello tom
Map阶段
1.每次读一行数据,
2.拆分每行数据,
3.每个单词碰到一次写个1
<0, "hello tom">
<10, "hello jerry">
<22, "hello kitty">
<34, "hello world">
<46, "hello tom">
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;
/**
* LongWritable 偏移量 long,表示该行在文件中的位置,而不是行号
* Text map阶段的输入数据 一行文本信息 字符串类型 String
* Text map阶段的数据字符串类型 String
* IntWritable map阶段输出的value类型,对应java中的int型,表示行号
*/
public class WordCountMap extends Mapper<LongWritable, Text, Text, IntWritable>{
@Override

本文档通过一个具体的例子展示了Hadoop MapReduce实现WordCount的过程。从原始数据开始,经过Map阶段,对每一行数据进行拆分并统计单词出现次数,然后在Reduce阶段将相同单词的计数进行求和。最后,输出每个单词及其总数。
最低0.47元/天 解锁文章
8680

被折叠的 条评论
为什么被折叠?



