2

"Mismatch in value class"MapReduce 2 への移行後に、レデューサーの単体テストで例外がスローされます。

Mismatch in value class: expected: class org.apache.hadoop.io.IntWritable actual: class com.company.MyWritable

エラー メッセージ自体は明らかですが、MRUnit が IntWritable ではなく一時的な書き込み可能なクラスを取得する理由がわかりません。

レデューサーの実装:

public static class TestCountReduce extends
        Reducer<Text, MyWritable, Text, IntWritable> {

    public void reduce(Text key, Iterator<MyWritable> values,
            Context context) throws IOException, InterruptedException {

        ...
        context.write(key, new IntWritable(s.size()));
    }
}

テストのセットアップ:

public void setUp() throws IOException {
    Mapper<Object, Text, Text, MyWritable> mapper = new MyMapper();
    Reducer<Text, MyWritable, Text, IntWritable> reducer = new MyReducer();

    mapDriver = new MapDriver<Object, Text, Text, MyWritable>();
    mapDriver.setMapper(mapper);

    reduceDriver = new ReduceDriver<Text, MyWritable, Text, IntWritable>();
    reduceDriver.setReducer(reducer);
}

そして最後にテストケース:

@Test
public void testReducer() throws IOException {
    List<MyWritable> values = new ArrayList<MyWritable>();
    values.add(new MyWritable("1"));
    values.add(new MyWritable("1"));
    reduceDriver.withInput(new Text("testkey"), values);
    reduceDriver.withOutput(new Text("testkey"), new IntWritable(1));
    reduceDriver.runTest();
}
4

1 に答える 1

2

reducer 実装の reduce メソッドの署名を確認してください

そのはず

public void reduce(Text key, Iterable<MyWritable> values, Context context) throws IOException, InterruptedException {

それ以外の

public void reduce(Text key, Iterator<MyWritable> values, Context context) throws IOException, InterruptedException {
于 2014-06-18T19:20:10.870 に答える