首页 文章

错误:java hadoop中预期的<identifier>

提问于
浏览
0

我正在为一个字数hadoop编译一个java文件,但是当它编译它时会抛出一个错误:

CountBook.java:33:错误:预期public void reduce(Text_key,Iteratorvalues,OutputCollectoroutput,Reporter reporter)抛出IOException

这是我的代码

public class CountBook
{
    public static class EMapper extends MapReducebase implements
    Mapper<LongWritable,Text,Text,IntWritable>
    {
        private final static Intwritable one = new Intwritable(1);
        public void map(LongWritable key,Text value,OutputCollector<Text,IntWritable>output,Reporter reporter)throws IOException
        {
            String line = value.toString();
            String[] Data = line.split("\";\"");
            output.collect(new text(Data[0]),one);

        }
    }


public static class EReduce extends MapReduceBase implements
Reducer<Text,IntWritable,Text,IntWritable>
{
    public void reduce(Text_key,Iterator<IntWritable>values,OutputCollector<text,intWritable>output,Reporter reporter)throws IOException
    {
        Text key=_key;
        int authid=0;
        while(values.hasNext())
        {
            IntWritable value = (IntWritable)values.next();
            authid+=value.get();
        }
        output.collect(key,new intWritable(authid));
    }
}


public static void main(String args[])throws Exception
{
    JobConf conf = new JbConf(CountBook.class);
    conf.setjobName("CountBookByAuthor");
    conf.setOutputkeyClass(Text.class);
    conf.setOutputValueClass(IntWritable.class);
    conf.setMapperClass(EMapper.class);
    conf.setCombinerClass(EReduce.class);
    conf.setReducerClass(EReducer.class);
    conf.setOutputFormat(TextOutputFormat.class);
    FileInputFormat.setInputPaths(conf,new path(args[0]));
    FileOutputFormat.setOutputPath(conf,new Path(args[1]));
    JobCLient.runJob(conf);
}
}

我正在使用hadoop-core-1.2.1.jar用于类路径库并在centos 7中运行

1 回答

  • 1

    你目前有:

    reduce(Text_key, 
           Iterator<IntWritable>values,
           OutputCollector<text,intWritable>output, 
           Reporter reporter)
    

    它应该是:

    reduce(Text key, 
           Iterator<IntWritable> values,
           OutputCollector<Text,IntWritable> output, 
           Reporter reporter)
    

    主要区别是 key 需要在它和 Text 之间留一个空格,并且 OutputCollector<> 中的类型需要使用capaptilized .

相关问题