【发布时间】:2012-04-12 07:55:30
【问题描述】:
我创建了一个 Mapper 和 Reducer,它使用 AVRO 作为输入、map-output 和 reduce 输出。创建 MRUnit 测试时,我得到以下堆栈跟踪:
java.lang.NullPointerException
at org.apache.hadoop.io.serializer.SerializationFactory.getSerializer(SerializationFactory.java:73)
at org.apache.hadoop.mrunit.mock.MockOutputCollector.deepCopy(MockOutputCollector.java:74)
at org.apache.hadoop.mrunit.mock.MockOutputCollector.collect(MockOutputCollector.java:110)
at org.apache.hadoop.mrunit.mapreduce.mock.MockMapContextWrapper$MockMapContext.write(MockMapContextWrapper.java:119)
at org.apache.avro.mapreduce.AvroMapper.writePair(AvroMapper.java:22)
at com.bol.searchrank.phase.day.DayMapper.doMap(DayMapper.java:29)
at com.bol.searchrank.phase.day.DayMapper.doMap(DayMapper.java:1)
at org.apache.avro.mapreduce.AvroMapper.map(AvroMapper.java:16)
at org.apache.avro.mapreduce.AvroMapper.map(AvroMapper.java:1)
at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:144)
at org.apache.hadoop.mrunit.mapreduce.MapDriver.run(MapDriver.java:200)
at org.apache.hadoop.mrunit.mapreduce.MapReduceDriver.run(MapReduceDriver.java:207)
at com.bol.searchrank.phase.day.DayMapReduceTest.shouldProduceAndCountTerms(DayMapReduceTest.java:39)
驱动初始化如下(我已经创建了一个 Avro MapReduce API 实现):
driver = new MapReduceDriver<AvroWrapper<Pair<Utf8, LiveTrackingLine>>, NullWritable, AvroKey<Utf8>, AvroValue<Product>, AvroWrapper<Pair<Utf8, Product>>, NullWritable>().withMapper(new DayMapper()).withReducer(new DayReducer());
使用 io.serialization 添加配置对象将无济于事:
Configuration configuration = new Configuration();
configuration.setStrings("io.serializations", new String[] {
AvroSerialization.class.getName()
});
driver = new MapReduceDriver<AvroWrapper<Pair<Utf8, LiveTrackingLine>>, NullWritable, AvroKey<Utf8>, AvroValue<Product>, AvroWrapper<Pair<Utf8, Product>>, NullWritable>().withMapper(new DayMapper()).withReducer(new DayReducer()).withConfiguration(configuration);
我使用 Cloudera 的 Hadoop 和 MRUnit 0.20.2-cdh3u2 和 Avro MapRed 1.6.3。
【问题讨论】:
-
您使用的是什么版本的mrunit,您是否在创建驱动程序之前配置了配置
io.serializations? -
配置是在驱动之前创建的,我按照这个更新了语句。还添加了版本号。
-
这里是否缺少更多代码 - 我收到 MapReduceDriver 构造函数行的编译错误:
Bound mismatch: The type AvroKey<Utf8> is not a valid substitute for the bounded parameter <K2 extends Comparable> of the type MapReduceDriver<K1,V1,K2,V2,K3,V3>。我可以对序列化工厂进行简单的单元测试(没有 MRUnit)