在我減速的代碼,我使用這個代碼片斷來概括值:Hadoop的 - 經典的MapReduce WORDCOUNT
for(IntWritable val : values) {
sum += val.get();
}
正如上面所說的給了我預期的輸出,我試圖改變代碼:
for(IntWritable val : values) {
sum += 1;
}
任何人都可以請解釋什麼是它使差異,當我在減速,而不是sum += val.get()
使用sum += 1
?爲什麼它給了我相同的輸出?是否有任何與合,因爲當我用這個相同的減速機代碼合成器,類輸出是不正確的用出1
映射代碼的計數的所有字:
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
String line = value.toString();
StringTokenizer token = new StringTokenizer(line);
while(token.hasMoreTokens()) {
word.set(token.nextToken());
context.write(word, new IntWritable(1));
}
}
減速器代號:
public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
int sum = 0;
for(IntWritable val : values) {
//sum += val.get();
sum += 1;
}
context.write(key, new IntWritable(sum));
}
驅動代碼:
job.setJarByClass(WordCountWithCombiner.class);
//job.setJobName("WordCount");
job.setMapperClass(WordCountMapper.class);
job.setCombinerClass(WordCountReducer.class);
job.setReducerClass(WordCountReducer.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(IntWritable.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
輸入 - 「要或不要是」
預期輸出 - (是,2),(對,2),(或1),(沒有,1)
但是輸出我得到爲 - (是,1),( (或1),(不是,1)
很好解釋。謝謝。 –