map中键的类型不匹配:应为org.apache.hadoop.io.text,收到org.apache.hadoop.io.longwritable

x6h2sr28  于 2021-05-29  发布在  Hadoop
关注(0)|答案(1)|浏览(397)
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));
        }
    }

这是我写的mapper方法,但是我得到了上面的错误。

a9wyjsp7

a9wyjsp71#

问题在于:

public class sortmapper extends Mapper<LongWritable,Text,Text,DoubleWritable> {
        public void map(Text key, Iterable<DoubleWritable> value, Context
``` `Mapper<LongWritable,Text,Text,DoubleWritable>` 对于Map器,输入键和值为:

LongWritable and Text

输出键和值为:

Text and DoubleWritable

还有你的 `map()` 签名应为:

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

相关问题