I am working through the WordCount example to get rid of all the deprecation
warnings.  While running it, my reduce function isn't being called.  Any
ideas?  The code below can also be found here: http://gist.github.com/346975

Thanks!
Chris

package hadoop.examples;

import java.io.IOException;
import java.util.*;

import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;

public class WordCount extends Configured implements Tool {

        public static class Map extends Mapper<LongWritable, Text, Text,
IntWritable> {
                private final static IntWritable one = new IntWritable(1);
                private Text word = new Text();

                public void map(LongWritable key, Text value, Context context)
                                throws IOException, InterruptedException {
                        String line = value.toString();
                        StringTokenizer tokenizer = new StringTokenizer(line);
                        while (tokenizer.hasMoreTokens()) {
                                word.set(tokenizer.nextToken());
                                context.write(word, one);
                        }
                }
        }

        public static class Reduce extends Reducer<Text, IntWritable, Text,
IntWritable> {
                public void reduce(Text key, Iterator<IntWritable> values, 
Context
context)
                                throws IOException, InterruptedException {
                        int sum = 0;
                        while (values.hasNext()) {
                                sum += values.next().get();
                        }
                        context.write(key, new IntWritable(sum));
                }
        }

        public static void main(String[] args) throws Exception {
                int res = ToolRunner.run(new Configuration(), new WordCount(), 
args);
                System.exit(res);
        }

        @Override
        public int run(String[] args) throws Exception {
                Configuration conf = getConf();
                Job job = new Job(conf, "wordcount");

                job.setJarByClass(WordCount.class);
                job.setMapperClass(Map.class);
                job.setReducerClass(Reduce.class);
                //job.setCombinerClass(Reduce.class);

                job.setInputFormatClass(TextInputFormat.class);
                job.setOutputFormatClass(TextOutputFormat.class);
                
                job.setOutputKeyClass(Text.class);
                job.setOutputValueClass(IntWritable.class);

                FileInputFormat.addInputPath(job, new Path(args[0]));
                FileOutputFormat.setOutputPath(job, new Path(args[1]));

                return job.waitForCompletion(true) ? 0 : 1;
        }
}

-- 
View this message in context: 
http://n3.nabble.com/Error-converting-WordCount-to-v0-20-x-tp682061p682061.html
Sent from the Users mailing list archive at Nabble.com.

Reply via email to