0

I was reading and implementing this tutorial. At the last, I implement the three classes- Mapper, Reducer and driver. I copied the exact code given on the webpage for all three classes. But following two errors didn't go away:-

Mapper Class

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 error was:

The type WordCountMapper must implement the inherited abstract method Mapper.map(LongWritable, Text, OutputCollector, Reporter)

Driver Class (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();
     }
 }
 }

The error was:

  1. FileInputPath cannot be resolved
  2. FileOutputPath cannot be resolved
vefthym
  • 7,422
  • 6
  • 32
  • 58
vishal
  • 1

1 Answers1

0

Use this

FileInputFormat.addInputPath(conf, new Path(args[0]));
        FileOutputFormat.setOutputPath(conf,new Path(args[1]));
                or
        FileInputFormat.addInputPath(conf, new Path("inputfile.txt"));
        FileOutputFormat.setOutputPath(conf,new Path("outputfile.txt"));

instead of this

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

This should be the one to import in this case

import org.apache.hadoop.mapred.FileInputFormat;
import org.apache.hadoop.mapred.FileOutputFormat;