java - 错误 : java. io.IOException : wrong value class: class org. apache.hadoop.io.Text 不是类 Myclass

标签 java hadoop elastic-map-reduce

我的映射器和缩减器如下。但是我遇到了一些奇怪的异常。 我不明白为什么会抛出这种异常。

public static class MyMapper implements Mapper<LongWritable, Text, Text, Info> {

    @Override
    public void map(LongWritable key, Text value,
        OutputCollector<Text, Info> output, Reporter reporter)
        throws IOException {
        Text text = new Text("someText")
            //process 
        output.collect(text, infoObjeject);
    }

}

public static class MyReducer implements Reducer<Text, Info, Text, Text> {

    @Override
    public void reduce(Text key, Iterator<Info> values,
        OutputCollector<Text, Text> output, Reporter reporter)
        throws IOException {
        String value = "xyz" //derived in some way
        //process
        output.collect(key, new Text(value)); //exception occurs at this line
    }

}

System.out.println("Starting v14 ");
JobConf conf = new JobConf(RouteBuilderJob.class);
conf.setJobName("xyz");

String jarLocation =ClassUtil.findContainingJar(getClass());

System.out.println("path of jar file = " + jarLocation);

conf.setJarByClass(RouteBuilderJob.class);

conf.setMapOutputKeyClass(Text.class);
conf.setMapOutputValueClass(Info.class);

conf.setOutputKeyClass(Text.class);
conf.setOutputValueClass(Text.class);

//am i missing something here???

conf.setMapperClass(RouteBuilderJob.RouteMapper.class);
conf.setCombinerClass(RouteBuilderJob.RouteReducer.class);
conf.setReducerClass(RouteBuilderJob.RouteReducer.class);


conf.setInputFormat(TextInputFormat.class);
conf.setOutputFormat(TextOutputFormat.class);

FileInputFormat.setInputPaths(conf, new Path(args[0]));
FileOutputFormat.setOutputPath(conf, new Path(args[1]));

JobClient.runJob(conf);

我遇到异常:

Error: java.io.IOException: wrong value class: class org.apache.hadoop.io.Text is not class com.xyz.mypackage.Info
at org.apache.hadoop.mapred.IFile$Writer.append(IFile.java:199)
at org.apache.hadoop.mapred.Task$CombineOutputCollector.collect(Task.java:1307)
at com.xyz.mypackage.job.MyJob$RouteReducer.reduce(MyJob.java:156)
at com.xyz.mypackage.job.MyJob$RouteReducer.reduce(MyJob.java:1)

内部信息对象(实现Writable)使用Text序列化

@Override
public void write(DataOutput out) throws IOException {
    Gson gson = new Gson();
    String searlizedStr = gson.toJson(this);
    Text.writeString(out, searlizedStr);
}

@Override
public void readFields(DataInput in) throws IOException {
    String s = Text.readString(in);
    Gson gson = new Gson();
    JsonReader jsonReader = new JsonReader(new StringReader(s));
    jsonReader.setLenient(true);

Info info = gson.fromJson(jsonReader, Info.class);
    //set fields using this.somefield = info.getsomefield() 
}

最佳答案

从技术上讲,reduce 的输出类型应该与输入类型相同。如果您使用组合器,则必须如此,因为组合器的输出被馈送到您的 reducer 中。

关于java - 错误 : java. io.IOException : wrong value class: class org. apache.hadoop.io.Text 不是类 Myclass,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21377011/

相关文章:

hadoop - 如何在 Hadoop 的 Mapper 和 Reducer 中提供子类?

hadoop - 如果我将相同的路径添加到 Hadoop 两次会发生什么?

java - assertTrue() 没有抛出 AssertionError

java - 在 Maven 构建期间,第二个主类覆盖第一个主类

scala - 如何使用值降序排列我的 Spark 结果元组

hadoop - 测量数据节点的吞吐量

python - 如何使用 s3 对象名称作为 MRJob 映射器的输入,而不是 s3 对象本身?

amazon-ec2 - AWS 弹性 map 上的加入性能减少运行配置单元

java - 在 ListView 中获取长按的内容

java - XML配置到字符串