我正在阅读并实现this教程。最后,我实现了三个类-Mapper,Reducer和driver。我复制了网页上所有三个类别的确切代码。但是以下两个错误并没有消失:-

*****************映射器类*********************************** ******************************

import java.io.IOException;
import java.util.StringTokenizer;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.Mapper;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reporter;

public class WordCountMapper extends MapReduceBase    //////Here WordCountMapper was underlined as error source by Eclipse
    implements Mapper<LongWritable, Text, Text, IntWritable> {

  private final IntWritable one = new IntWritable(1);
  private Text word = new Text();

  public void map(WritableComparable key, Writable value,
      OutputCollector output, Reporter reporter) throws IOException {

    String line = value.toString();
    StringTokenizer itr = new StringTokenizer(line.toLowerCase());
    while(itr.hasMoreTokens()) {
      word.set(itr.nextToken());
      output.collect(word, one);
    }
  }
}

错误是:
The type WordCountMapper must implement the inherited abstract method
 Mapper<LongWritable,Text,Text,IntWritable>.map(LongWritable, Text,
 OutputCollector<Text,IntWritable>, Reporter)

**********************驱动程序类(WordCount.java)********************* *************
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.FileInputFormat;
import org.apache.hadoop.mapred.FileOutputFormat;
import org.apache.hadoop.mapred.JobClient;
import org.apache.hadoop.mapred.JobConf;

public class WordCount {

  public static void main(String[] args) {
    JobClient client = new JobClient();
    JobConf conf = new JobConf(WordCount.class);

    // specify output types
    conf.setOutputKeyClass(Text.class);
    conf.setOutputValueClass(IntWritable.class);

    // specify input and output dirs
    FileInputPath.addInputPath(conf, new Path("input"));  //////////FileInputPath was underlined
    FileOutputPath.addOutputPath(conf, new Path("output")); ////////FileOutputPath as underlined

    // specify a mapper
    conf.setMapperClass(WordCountMapper.class);

    // specify a reducer
    conf.setReducerClass(WordCountReducer.class);
    conf.setCombinerClass(WordCountReducer.class);

    client.setConf(conf);
    try {
      JobClient.runJob(conf);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

错误是:
1. FileInputPath cannot be resolved
2. FileOutputPath cannot be resolved

有人可以告诉我问题是什么吗?提前致谢。

最佳答案

正如Sachinjose所说,第二个错误在我将代码更改为:

 FileInputFormat.addInputPath(conf, new Path("input"));
    FileOutputFormat.setOutputPath(conf, new Path("output"));

也是在this示例中解决了第一个错误(我正在复制user2357112的答案):-

您尚未提供任何类型参数。映射器是通用接口(interface);它使用输入和输出键以及值类型的类型参数进行参数化。在以下代码中使用所需的类型填写K1,V1,K2和V2:
public class WordMapper extends MapReduceBase implements Mapper<K1, V1, K2, V2> {
    public void map(K1 key,
                    V1 value,
                    OutputCollector<K2, V2> output,
                    Reporter reporter)
            throws IOException {
        whatever();
    }
}

10-06 08:48
查看更多