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 protected void map(LongWritable key,Text value,Context context)throws IOException,InterruptedException{ //读取每行文本 String line=value.toString(); //splite拆分每行 String[] words=line.split(" ");//分词 //取出每个单词 for(String word:words){ //将单词转为Text类型 Text wordText=new Text(word); //将1转变为IntWritable IntWritable outValue=new IntWritable(1); //写出单词,跟对应1
hadoop_WordCountMap
最新推荐文章于 2023-05-05 17:49:26 发布