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方法,但出现上述错误。
最佳答案
问题在这里:
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)
关于hadoop - map 中 key 的类型不匹配:预期的org.apache.hadoop.io.Text,收到的org.apache.hadoop.io.LongWritable,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34590567/