MapReduce ジョブで Avro を使用すると、静かで奇妙な動作が見られました。実際、使用されている Iterable は非常に奇妙です: iterator.next はオブジェクトを指すのではなく、関数「next」の呼び出しごとに値が変化するものを指します!!
例 :
public static class MyAvroReducer extends AvroReducer<Long, MyAvroType,
Pair<Long, MyAvroType>> {
@Override
public void reduce(Long user, Iterable<MyAvroType> listAvroType,
AvroCollector<Pair<Long,MyAvroType>> collector,
Reporter reporter)
throws IOException {
// basically here I am expecting a list of two MyAvroType object
// The first one who has a field "type" equals to "foo" and the second
// who has a filed "type" equals to "bar"
MyAvroType foo;
MyAvroType bar;
for (MyAvroType obj : listAvroType){
if (obj.getType().equals("foo") {foo = obj;}
else if (obj.getType().equals("bar") {bar = obj;}
}
system.out.println("FOO: " + foo.getType());
system.out.println("FOO: " + bar.getType());
}
標準出力には次のように表示されます。
フー:バー
BAR:バー
ここで Iterable はどのようにコーディングされていますか? なぜ ??それとも私は何か間違ったことをしていますか?