Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Hadoop的MapReduce:类型不匹配_Hadoop_Mapreduce - Fatal编程技术网

使用Hadoop的MapReduce:类型不匹配

使用Hadoop的MapReduce:类型不匹配,hadoop,mapreduce,Hadoop,Mapreduce,我正在运行一个简单的hadoop程序,出现以下错误: java.io.IOException: Type mismatch in key from map: expected org.apache.hadoop.io.Text, recieved org.apache.hadoop.io.LongWritable 制图员: public static class myMapper extends Mapper<LongWritable, Text, Text, Text> publ

我正在运行一个简单的hadoop程序,出现以下错误:

java.io.IOException: Type mismatch in key from map: expected org.apache.hadoop.io.Text, recieved org.apache.hadoop.io.LongWritable
制图员:

public static class myMapper extends Mapper<LongWritable, Text, Text, Text>
public void map(LongWritable key, Text line,OutputCollector<Text,Text> output, Reporter reporter) throws IOException, InterruptedException

如何修复此问题???

看起来您在使用新的API类(您的映射器扩展了mapred.mapper),但您已经使用旧的API编写了映射方法(您正在使用OutputCollector和Reporter)

将映射器映射签名和reducer reduce方法更改为以下内容:

public void map(LongWritable key, Text value, Context context) { .. }
public void reduce(Text key, Iterable<Text> value, Context context) { .. }
public void映射(LongWritable键、文本值、上下文){..}
public void reduce(文本键、Iterable值、上下文){..}

如果在方法上方添加
@Override
注释也会有所帮助,如果签名错误,这将导致编译器失败。

是否设置了映射器类?看起来您正在获得IdentityMapper输出。请发布完整的作业配置
...
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(Text.class);
...
public void map(LongWritable key, Text value, Context context) { .. }
public void reduce(Text key, Iterable<Text> value, Context context) { .. }