Changes between Initial Version and Version 1 of Hadoop_Lab4_hello_018


Ignore:
Timestamp:
Mar 3, 2010, 12:14:04 PM (14 years ago)
Author:
waue
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Hadoop_Lab4_hello_018

    v1 v1  
     1{{{
     2#!java
     3import java.io.IOException;
     4import java.util.Iterator;
     5
     6import org.apache.hadoop.fs.Path;
     7import org.apache.hadoop.io.LongWritable;
     8import org.apache.hadoop.io.Text;
     9import org.apache.hadoop.mapred.FileInputFormat;
     10import org.apache.hadoop.mapred.FileOutputFormat;
     11import org.apache.hadoop.mapred.JobClient;
     12import org.apache.hadoop.mapred.JobConf;
     13import org.apache.hadoop.mapred.MapReduceBase;
     14import org.apache.hadoop.mapred.Mapper;
     15import org.apache.hadoop.mapred.OutputCollector;
     16import org.apache.hadoop.mapred.Reducer;
     17import org.apache.hadoop.mapred.Reporter;
     18import org.apache.hadoop.mapred.TextInputFormat;
     19import org.apache.hadoop.mapred.TextOutputFormat;
     20
     21public class Hello {
     22
     23        public static class Map extends MapReduceBase implements
     24                        Mapper<LongWritable, Text, LongWritable, Text> {
     25
     26                public void map(LongWritable key, Text value,
     27                                OutputCollector<LongWritable, Text> output, Reporter reporter)
     28                                throws IOException {
     29
     30                        output.collect(key, value);
     31                }
     32        }
     33
     34        public static class Reduce extends MapReduceBase implements
     35                        Reducer<LongWritable, Text, LongWritable, Text> {
     36                Text ret = new Text("");
     37
     38                public void reduce(LongWritable key, Iterator<Text> values,
     39                                OutputCollector<LongWritable, Text> output, Reporter reporter)
     40                                throws IOException {
     41
     42                        while (values.hasNext()) {
     43                                ret = values.next();
     44                        }
     45                        output.collect(key, ret);
     46                }
     47        }
     48
     49        public static void main(String[] args) throws Exception {
     50                JobConf conf = new JobConf(Hello.class);
     51                conf.setJobName("Hello");
     52
     53                conf.setMapperClass(Map.class);
     54                conf.setCombinerClass(Reduce.class);
     55                conf.setReducerClass(Reduce.class);
     56                conf.setMapOutputKeyClass(LongWritable.class);
     57                conf.setMapOutputValueClass(Text.class);
     58                conf.setOutputKeyClass(LongWritable.class);
     59                conf.setOutputValueClass(Text.class);
     60
     61                conf.setInputFormat(TextInputFormat.class);
     62                conf.setOutputFormat(TextOutputFormat.class);
     63
     64                FileInputFormat.setInputPaths(conf, new Path(args[0]));
     65                FileOutputFormat.setOutputPath(conf, new Path(args[1]));
     66
     67                JobClient.runJob(conf);
     68        }
     69}
     70
     71}}}