fork download
  1. import java.io.*;
  2. import org.apache.hadoop.conf.*;
  3. import org.apache.hadoop.fs.Path;
  4. import org.apache.hadoop.io.*;
  5. import org.apache.hadoop.mapreduce.*;
  6. import org.apache.hadoop.mapreduce.lib.input.*;
  7. import org.apache.hadoop.mapreduce.lib.output.*;
  8.  
  9. public class Main {
  10.  
  11. public static class Map extends Mapper<LongWritable, Text, Text, IntWritable> {
  12. public void map(LongWritable key, Text value, Context c) throws IOException, InterruptedException {
  13. String line = value.toString();
  14. if(line.split(" ").length > 5)
  15. c.write(new Text("count"), new IntWritable(1));
  16. }
  17. }
  18.  
  19. public static class Reduce extends Reducer<Text, IntWritable, Text, IntWritable> {
  20. public void reduce(Text key, Iterable<IntWritable> v, Context c) throws IOException, InterruptedException {
  21. int sum = 0;
  22. for(IntWritable x : v) sum += x.get();
  23. c.write(key, new IntWritable(sum));
  24. }
  25. }
  26.  
  27. public static void main(String[] args) throws Exception {
  28. Configuration conf = new Configuration();
  29. Job job = Job.getInstance(conf, "job");
  30.  
  31. job.setJarByClass(Main.class);
  32. job.setMapperClass(Map.class);
  33. job.setReducerClass(Reduce.class);
  34.  
  35. job.setOutputKeyClass(Text.class);
  36. job.setOutputValueClass(IntWritable.class);
  37.  
  38. FileInputFormat.addInputPath(job, new Path(args[0]));
  39. FileOutputFormat.setOutputPath(job, new Path(args[1]));
  40.  
  41. System.exit(job.waitForCompletion(true) ? 0 : 1);
  42. }
  43. }
Success #stdin #stdout #stderr 0.02s 6804KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/pE2ltK/prog:43:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit