[學習筆記] /*org.apache.hadoop.mapreduce.Mapper.Context,java.lang.InterruptedException,想看map的源代碼,按control,點擊,出現Attach Source Code,點擊External Location/Exte ...
[學習筆記]
/*org.apache.hadoop.mapreduce.Mapper.Context,java.lang.InterruptedException,想看map的源代碼,按control,點擊,出現Attach Source Code,點擊External Location/External File,找到源代碼,就在Source目錄下,,D:\hadoop-2.7.4\src
其中key為此行的開頭相對於文件的起始位置,value就是此行的字元文本
*/ public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
System.out.println("key is 馬克-to-win @ 馬克java社區 "+key.toString()+" value is "+value.toString());
StringTokenizer itr = new StringTokenizer(value.toString());
while (itr.hasMoreTokens()) {
word.set(itr.nextToken());
context.write(word, one);
}
}
}
public static class IntSumReducer extends Reducer<Text, IntWritable, Text, IntWritable> {
private IntWritable result = new IntWritable();
public void reduce(Text key, Iterable<IntWritable> values, Context context)
throws IOException, InterruptedException {
System.out.println("reduce key is 馬克-to-win @ 馬克java社區 "+key.toString());
int sum = 0;
for (IntWritable val : values) {
int valValue=val.get();
System.out.println("valValue is"+valValue);
sum += valValue ;
}
result.set(sum);
context.write(key, result);
}
}
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
if (otherArgs.length != 2) {
System.err.println("Usage: wordcount <in> <out>");
System.exit(2);
}
Job job = new Job(conf, "word count");
job.setJarByClass(WordCount.class);
job.setMapperClass(TokenizerMapper.class);
文章轉載自原文:https://blog.csdn.net/qq_44594249/article/details/96110661