我嘗試實施的話由我自己算例如,這裏是我的執行映射器:地圖減少字數例如不工作
public static class Map extends Mapper<LongWritable, Text, Text, IntWritable> {
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
Text word = new Text();
String line = value.toString();
StringTokenizer tokenizer = new StringTokenizer(line);
while (tokenizer.hasMoreTokens()) {
word.set(tokenizer.nextToken());
context.write(word, new IntWritable(1));
}
}
}
和減速機:
public static class Reduce extends Reducer<Text, IntWritable, Text, IntWritable> {
public void reduce(Text key, Iterator<IntWritable> values, Context context) throws IOException, InterruptedException {
int sum = 0;
while (values.hasNext())
sum += values.next().get();
context.write(key, new IntWritable(sum));
}
}
但輸出我得到執行此代碼看起來像只映射器的輸出,例如,如果輸入的是「世界你好你好」,輸出將爲
hello 1
hello 1
world 1
我也使用映射和縮減之間的組合器。任何人都可以解釋我這個代碼有什麼問題嗎?
非常感謝!
感謝。我被困在這個問題上一兩天了。 – rOrlig 2011-04-26 02:12:05