引起:java.lang.ClassCastException:org.apache.hadoop.io.LongWritable无法强制转换为org.apache.hadoop.io.Text

时间:2014-11-12 05:14:58

标签: hadoop github mapreduce bigdata uima

我正在尝试编译以下github项目https://github.com/DigitalPebble/behemoth/tree/master/uima

我收到以下错误java.lang.ClassCastException:org.apache.hadoop.io.LongWritable无法强制转换为org.apache.hadoop.io.Text

代码具有以下输出键和值类定义。其中BehemothDocument是定义的自定义类

                  job.setInputFormat(SequenceFileInputFormat.class);
                  job.setOutputFormat(SequenceFileOutputFormat.class);
                  job.setMapOutputKeyClass(Text.class);
                  job.setMapOutputValueClass(BehemothDocument.class);
                  job.setOutputKeyClass(Text.class);
                  job.setOutputValueClass(BehemothDocument.class);

地图类如下所示

public class UIMAMapper extends MapReduceBase implements
    Mapper<Text, BehemothDocument, Text, BehemothDocument> {

和Map功能如下

public void map(Text id, BehemothDocument behemoth,
OutputCollector<Text, BehemothDocument> output, Reporter reporter)

我已经看到了几个关于堆栈溢出的上述错误的答案已经要求更改Mapper键,我不想做的值类型。我想知道如何使用自定义类。

请帮助解决这个问题。下面是堆栈跟踪信息

    java.lang.Exception: java.lang.ClassCastException: org.apache.hadoop.io.LongWritable cannot be cast to org.apache.hadoop.io.Text
    at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:354)
Caused by: java.lang.ClassCastException: org.apache.hadoop.io.LongWritable cannot be cast to org.apache.hadoop.io.Text
    at UIMAPackage.UIMAMapper.map(UIMAMapper.java:35)
    at org.apache.hadoop.mapred.MapRunner.run(MapRunner.java:50)
    at org.apache.hadoop.mapred.MapTask.runOldMapper(MapTask.java:430)
    at org.apache.hadoop.mapred.MapTask.run(MapTask.java:366)
    at org.apache.hadoop.mapred.LocalJobRunner$Job$MapTaskRunnable.run(LocalJobRunner.java:223)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)

1 个答案:

答案 0 :(得分:1)

而不是Text使用LongWritable作为映射器的输入键类型。 它应该工作。