fork download
  1. package com.javatpoint;
  2.  
  3. import java.io.IOException;
  4. import org.apache.hadoop.io.IntWritable;
  5. import org.apache.hadoop.io.LongWritable;
  6. import org.apache.hadoop.io.Text;
  7. import org.apache.hadoop.mapred.MapReduceBase;
  8. import org.apache.hadoop.mapred.Mapper;
  9. import org.apache.hadoop.mapred.OutputCollector;
  10. import org.apache.hadoop.mapred.Reporter;
  11. public class WC_Mapper extends MapReduceBase implements Mapper<LongWritable,Text,Text,IntWritable>{
  12. public void map(LongWritable key, Text value,OutputCollector<Text,IntWritable> output,
  13. Reporter reporter) throws IOException{
  14. String line = value.toString();
  15. String tokenizer[] = line.split("");
  16. for(String SingleChar : tokenizer)
  17. {
  18. Text charKey = new Text(SingleChar);
  19. IntWritable One = new IntWritable(1);
  20. output.collect(charKey, One);
  21. }
  22. }
  23.  
  24. }
  25. File: WC_Reducer.java
  26. package com.javatpoint;
  27. import java.io.IOException;
  28. import java.util.Iterator;
  29. import org.apache.hadoop.io.IntWritable;
  30. import org.apache.hadoop.io.Text;
  31. import org.apache.hadoop.mapred.MapReduceBase;
  32. import org.apache.hadoop.mapred.OutputCollector;
  33. import org.apache.hadoop.mapred.Reducer;
  34. import org.apache.hadoop.mapred.Reporter;
  35.  
  36. public class WC_Reducer extends MapReduceBase implements Reducer<Text,IntWritable,Text,IntWritable> {
  37. public void reduce(Text key, Iterator<IntWritable> values,OutputCollector<Text,IntWritable> output,
  38. Reporter reporter) throws IOException {
  39. int sum=0;
  40. while (values.hasNext()) {
  41. sum+=values.next().get();
  42. }
  43. output.collect(key,new IntWritable(sum));
  44. }
  45. }
  46. File: WC_Runner.java
  47. package com.javatpoint;
  48.  
  49. import java.io.IOException;
  50. import org.apache.hadoop.fs.Path;
  51. import org.apache.hadoop.io.IntWritable;
  52. import org.apache.hadoop.io.Text;
  53. import org.apache.hadoop.mapred.FileInputFormat;
  54. import org.apache.hadoop.mapred.FileOutputFormat;
  55. import org.apache.hadoop.mapred.JobClient;
  56. import org.apache.hadoop.mapred.JobConf;
  57. import org.apache.hadoop.mapred.TextInputFormat;
  58. import org.apache.hadoop.mapred.TextOutputFormat;
  59. public class WC_Runner {
  60. public static void main(String[] args) throws IOException{
  61. JobConf conf = new JobConf(WC_Runner.class);
  62. conf.setJobName("CharCount");
  63. conf.setOutputKeyClass(Text.class);
  64. conf.setOutputValueClass(IntWritable.class);
  65. conf.setMapperClass(WC_Mapper.class);
  66. conf.setCombinerClass(WC_Reducer.class);
  67. conf.setReducerClass(WC_Reducer.class);
  68. conf.setInputFormat(TextInputFormat.class);
  69. conf.setOutputFormat(TextOutputFormat.class);
  70. FileInputFormat.setInputPaths(conf,new Path(args[0]));
  71. FileOutputFormat.setOutputPath(conf,new Path(args[1]));
  72. JobClient.runJob(conf);
  73. }
  74. }
Success #stdin #stdout #stderr 0.01s 5260KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: near line 1: near "package": syntax error
Error: near line 3: near "import": syntax error
Error: near line 4: near "import": syntax error
Error: near line 5: near "import": syntax error
Error: near line 6: near "import": syntax error
Error: near line 7: near "import": syntax error
Error: near line 8: near "import": syntax error
Error: near line 9: near "import": syntax error
Error: near line 10: near "import": syntax error
Error: near line 11: near "public": syntax error
Error: near line 15: near "String": syntax error
Error: near line 16: near "for": syntax error
Error: near line 19: near "IntWritable": syntax error
Error: near line 20: near "output": syntax error
Error: near line 21: unrecognized token: "}"
Error: near line 27: near "import": syntax error
Error: near line 28: near "import": syntax error
Error: near line 29: near "import": syntax error
Error: near line 30: near "import": syntax error
Error: near line 31: near "import": syntax error
Error: near line 32: near "import": syntax error
Error: near line 33: near "import": syntax error
Error: near line 34: near "import": syntax error
Error: near line 36: near "public": syntax error
Error: near line 40: near "while": syntax error
Error: near line 42: unrecognized token: "}"
Error: near line 44: unrecognized token: "}"
Error: near line 49: near "import": syntax error
Error: near line 50: near "import": syntax error
Error: near line 51: near "import": syntax error
Error: near line 52: near "import": syntax error
Error: near line 53: near "import": syntax error
Error: near line 54: near "import": syntax error
Error: near line 55: near "import": syntax error
Error: near line 56: near "import": syntax error
Error: near line 57: near "import": syntax error
Error: near line 58: near "import": syntax error
Error: near line 59: near "public": syntax error
Error: near line 62: near "conf": syntax error
Error: near line 63: near "conf": syntax error
Error: near line 64: near "conf": syntax error
Error: near line 65: near "conf": syntax error
Error: near line 66: near "conf": syntax error
Error: near line 67: near "conf": syntax error
Error: near line 68: near "conf": syntax error
Error: near line 69: near "conf": syntax error
Error: near line 70: near "FileInputFormat": syntax error
Error: near line 71: near "FileOutputFormat": syntax error
Error: near line 72: near "JobClient": syntax error
Error: near line 73: unrecognized token: "}"