从map中获取类型不匹配:期望org.apache.hadoop.io.Text,收到org.apache.hadoop.io.LongWritable错误

时间:2016-06-02 16:42:42

标签: java eclipse apache hadoop

我正在尝试使用eclipse在java中运行map / reducer。以下是我的代码

驱动程序代码:

package com.hadoop.training.criccount;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Set;
import javax.lang.model.SourceVersion;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import com.hadoop.training.hadooputility.HadoopUtility;
public class CricClickDriver extends Configured implements Tool{
    public int run (String args[]) throws Exception
    {
        Configuration config =HadoopUtility.INSTANCE.pseudomode();


        Job job = new Job(config, "No of clicks by location");
        job.setJarByClass(CricClickDriver.class);

        job.setInputFormatClass(TextInputFormat.class);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(LongWritable.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(LongWritable.class);

        job.setMapperClass(CricClickMapper.class);
        job.setReducerClass(CricClickReducer.class);

        FileInputFormat.addInputPath(job, new Path(args[0]));
        FileOutputFormat.setOutputPath(job, new Path(args[1]));

        int exitcode = job.waitForCompletion(true)? 0:1;
        return exitcode;
    }
}

映射器代码:

package com.hadoop.training.criccount;
import java.io.IOException;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
@SuppressWarnings("unused")
public class CricClickMapper extends Mapper<LongWritable, Text,Text, LongWritable>{

    public void CricketClick(LongWritable key, Text value, Context output)     throws IOException, InterruptedException
    {

         String Line= value.toString();
         String part[]=Line.split(" ");

         if(part[0].contains("BAN"))  
         {
            output.write(new Text(part[1]),new         LongWritable(Long.parseLong(part[2])));    
         }

    }
}

减速机代码:

package com.hadoop.training.criccount;
import java.io.IOException;
import java.util.Iterator;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
public class CricClickReducer extends Reducer<Text, LongWritable, Text,     LongWritable>{
    public void reduce(Text key, Iterable<LongWritable> value, Context     output) throws IOException, InterruptedException
    {
        int sum=0;
        for(LongWritable val:value){

            sum +=val.get();
        }
        output.write(key, new LongWritable(sum));
    }
}

我收到以下错误: 键入地图

中的不匹配项

我尝试调试但无法找到rootcause。需要帮助。

1 个答案:

答案 0 :(得分:0)

您的Mapper类定义与documentation中提到的类似。

public class Mapper<KEYIN,VALUEIN,KEYOUT,VALUEOUT>

或者它是否在您在此处发布的代码中不可见?