hadoop-mapreduce-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Zhang <zjf...@gmail.com>
Subject Re: Question regarding wordCount example
Date Mon, 26 Oct 2009 02:56:41 GMT
Hi gao,

You did not provider the type of key and value explicitly in your code, so
you have to write your map method as

public void map(Object key, Object value, OutputCollector output,
        Reporter reporter) throws IOException {
    // TODO Auto-generated method stub

}

But I suggest you write your Mapper class like this

public class WordCountMapper extends MapReduceBase
    implements Mapper<Long,Text,Text,Long>{
     public void map(Long key, Text value, OutputCollector<Text, Long>
output,
        Reporter reporter) throws IOException {
    // TODO Auto-generated method stub

     }
}

using generic as possible as you can



Jeff zhang


On Mon, Oct 26, 2009 at 6:35 AM, felix gao <gre1600@gmail.com> wrote:

> Hi all, I have some question regarding how to compile a simple hadoop
> program.
>
> setup
> Java 1.6
> Ubuntu 9.02
> Hadoop 0.19.2
>
>
> //below is the 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
>     implements Mapper{
>
>   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);
>     }
>   }
>
> }
>
>
>
> here is the error message:
> javac -classpath "/home/hadoop-user/hadoop-0.19/hadoop-0.19.2-core.jar"
> *.java
> WordCountMapper.java:14: WordCountMapper is not abstract and does not
> override abstract method
> map(java.lang.Object,java.lang.Object,org.apache.hadoop.mapred.OutputCollector,org.apache.hadoop.mapred.Reporter)
> in org.apache.hadoop.mapred.Mapper
> public class WordCountMapper extends MapReduceBase
>        ^
> Note: Some input files use unchecked or unsafe operations.
> Note: Recompile with -Xlint:unchecked for details.
> 1 error
>
> Can someone tell me what is going on here.
>
> Thanks,
>
> Felix
>
>
>

Mime
View raw message