键入map中的键不匹配:期望org.apache.hadoop.io.Text,收到org.apache.hadoop.io.LongWritable

时间:2016-01-04 11:53:26

标签: hadoop mapreduce mapper bigdata

    package Sort;
    import java.io.IOException;
    import org.apache.hadoop.io.DoubleWritable;
    import org.apache.hadoop.io.LongWritable;
    import org.apache.hadoop.io.Text;
    import org.apache.hadoop.mapreduce.Mapper;
    public class sortmapper extends                  Mapper<LongWritable,Text,Text,DoubleWritable> {
        public void map(Text key, Iterable<DoubleWritable> value, Context                            context) throws IOException, InterruptedException {
            String line = value.toString();
            String subId = line.substring(15, 26);
            Double bytes = Double.parseDouble(line.substring(45, 56));
            if (bytes == null) 
                bytes = 0.0;
            context.write(new Text(subId),new DoubleWritable(bytes));
        }
    }

这是我编写的映射器方法,但我收到了上述错误。

1 个答案:

答案 0 :(得分:0)

问题在于:

  public class sortmapper extends Mapper<LongWritable,Text,Text,DoubleWritable> {
        public void map(Text key, Iterable<DoubleWritable> value, Context      

<强> Mapper<LongWritable,Text,Text,DoubleWritable>

对于您的映射器,输入键和值为:

LongWritable and Text

输出键和值为:

Text and DoubleWritable

您的map()签名应为:

public void map(LongWritable key, Text value, Context context)