私はhadoopを使ってmapreduceプログラムで作業しています。私は減速中のコードのこの部分を持っている
:私は値を二回繰り返すためにhereを見たよう2回目の反復 - 値は同じままです
public void reduce(Text key, Iterable<TextLongWritable> values,Context context) throws IOException, InterruptedException {
long word1count = 0;
List<TextLongWritable> cache = new ArrayList<TextLongWritable>();
String decade = key.toString().split("\t")[0];
String word1 = key.toString().split("\t")[1];
for (TextLongWritable val : values) {
if (val.getWord().equals("*")){
word1count += val.getCount();
continue;
}
cache.add(val);
log.info("***Reducer*** Word1: " + word1 + " Word2: " + val.getWord());
}
context.write(key, new Text("" + word1count));
for (TextLongWritable value : cache) {
if (value.getWord().equals("*")){
continue;
}
log.info("***Reducer*** Word1: " + word1 + " Word2: " + value.getWord());
context.write(new Text(decade + "\t" + value.getWord()), new Text(word1 + " " + value.getCount() + "\t" + word1count));
}
}
まず、私はキャッシュを使用しています。
私の問題は、2番目のループでは、すべての値が変わらないことです。たとえば、単語がone
two
three
のリストがあるとします。キーが1900 test
なので、word1 = "test"
と言います。
最初ロガーの出力は次のようになります。
***Reducer*** Word1: test Word2: one
***Reducer*** Word1: test Word2: two
***Reducer*** Word1: test Word2: three
しかし二ロガー出力は次のようになります。
***Reducer*** Word1: test Word2: one
***Reducer*** Word1: test Word2: one
***Reducer*** Word1: test Word2: one
値が何らかの理由で同じまま。
ここで何が間違っていますか?それはハープと何か関係がありますか?