AvinashK
AvinashK

Reputation: 3423

Hadoop integration with Eclipse

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<LongWritable,Text,Text,IntWritable>.map(LongWritable, Text, 
 OutputCollector<Text,IntWritable>, 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

Can somebody tell me what the problem is? Thanks in advance.

Upvotes: 2

Views: 1812

Answers (2)

AvinashK
AvinashK

Reputation: 3423

As Sachinjose said, the second error was solved when I changed code to:-

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

Also the first error is solved in this example(I am copying the answer of user2357112):-

You haven't provided any of the type parameters. Mapper is a generic interface; it's parameterized with type parameters for the input and output key and value types. Fill in K1, V1, K2, and V2 in the following code with the types you need:

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

Upvotes: 4

SachinJose
SachinJose

Reputation: 8522

Use org.apache.hadoop.mapred.FileInputFormat , org.apache.hadoop.mapred.FileOutputFormat and modify your code as follows :

    // specify input and output dirs
    FileInputFormat.addInputPath(conf, new Path("input"));  
    FileOutputFormat.addOutputPath(conf, new Path("output"));

Upvotes: 2

Related Questions