classcastexception

4sup72z8  于 2021-06-03  发布在  Hadoop
关注(0)|答案(0)|浏览(237)

我使用的是mrunit0.9.0、avro 1.7.0和hadoop 0.20.205.0。
我已配置 mapDriver 具体如下:

@Before
public void setup()
{
    AvroWordCount.Map mapper = new AvroWordCount.Map();
    AvroWordCount.Reduce reducer = new AvroWordCount.Reduce();
    Configuration conf = new Configuration();
    conf.setStrings( "io.serializations", new String[] { AvroSerialization.class.getName(), WritableSerialization.class.getName() } );
    AvroSerialization.setValueWriterSchema( conf, AvroWordCount.SCHEMA_COUNT );
    AvroSerialization.setValueReaderSchema( conf, AvroWordCount.SCHEMA_COUNT  );
    AvroSerialization.addToConfiguration(conf);
    mapDriver = new MapDriver<AvroKey<Line>, NullWritable, Text, AvroValue<Count>>( mapper ).withConfiguration( conf );

}

调用mapdriver.run()会出现以下异常:

java.lang.ClassCastException: amazon.fclm.labormetrics.mapreduce.sample.AvroWordCount$Count cannot be cast to org.apache.avro.generic.IndexedRecord
    at org.apache.avro.generic.GenericData.getField(GenericData.java:518)
    at org.apache.avro.generic.GenericData.getField(GenericData.java:533)
    at org.apache.avro.generic.GenericDatumWriter.writeRecord(GenericDatumWriter.java:103)
    at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:65)
    at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:57)
    at org.apache.avro.hadoop.io.AvroSerializer.serialize(AvroSerializer.java:103)
    at org.apache.avro.hadoop.io.AvroSerializer.serialize(AvroSerializer.java:45)
    at org.apache.hadoop.mrunit.Serialization.copy(Serialization.java:62)
    at org.apache.hadoop.mrunit.Serialization.copy(Serialization.java:81)
    at org.apache.hadoop.mrunit.mapreduce.mock.MockContextWrapper$4.answer(MockContextWrapper.java:78)
    at org.mockito.internal.stubbing.StubbedInvocationMatcher.answer(StubbedInvocationMatcher.java:34)
    at org.mockito.internal.MockHandler.handle(MockHandler.java:99)
    at org.mockito.internal.InvocationNotifierHandler.handle(InvocationNotifierHandler.java:36)
    at org.mockito.internal.creation.MethodInterceptorFilter.intercept(MethodInterceptorFilter.java:48)
    at org.apache.hadoop.mapreduce.Mapper$Context$$EnhancerByMockitoWithCGLIB$$4ae1b65a.write(<generated>)
    at amazon.fclm.labormetrics.mapreduce.sample.AvroWordCount$Map.map(AvroWordCount.java:76)
    at amazon.fclm.labormetrics.mapreduce.sample.AvroWordCount$Map.map(AvroWordCount.java:1)
    at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:144)
    at org.apache.hadoop.mrunit.mapreduce.MapDriver.run(MapDriver.java:221)
    at amazon.fclm.labormetrics.mapreduce.sample.AvroWordCountTest.TestMrUnitMapper(AvroWordCountTest.java:61)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

我也找不到任何avro+mrunit+hadoop的例子。如果有人有什么建议,那就太好了。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题