fork download
  1. import org.apache.hadoop.conf.Configuration;
  2. import org.apache.hadoop.fs.Path;
  3. import org.apache.hadoop.io.BytesWritable;
  4. import org.apache.hadoop.io.NullWritable;
  5. import org.apache.hadoop.mapreduce.Job;
  6. import org.apache.hadoop.mapreduce.Mapper;
  7. import org.apache.hadoop.mapreduce.Reducer;
  8. import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
  9. import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
  10. import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
  11. import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
  12.  
  13. import java.io.IOException;
  14.  
  15. public class BinarySort {
  16.  
  17. public static class BinaryMapper extends Mapper<NullWritable, BytesWritable, BytesWritable, NullWritable> {
  18. public void map(NullWritable key, BytesWritable value, Context context) throws IOException, InterruptedException {
  19. context.write(value, NullWritable.get());
  20. }
  21. }
  22.  
  23. public static class BinaryReducer extends Reducer<BytesWritable, NullWritable, BytesWritable, NullWritable> {
  24. public void reduce(BytesWritable key, Iterable<NullWritable> values, Context context) throws IOException, InterruptedException {
  25. context.write(key, NullWritable.get());
  26. }
  27. }
  28.  
  29. public static void main(String[] args) throws Exception {
  30. Configuration conf = new Configuration();
  31. Job job = Job.getInstance(conf, "Binary Sort");
  32. job.setJarByClass(BinarySort.class);
  33.  
  34. job.setMapperClass(BinaryMapper.class);
  35. job.setReducerClass(BinaryReducer.class);
  36.  
  37. job.setOutputKeyClass(BytesWritable.class);
  38. job.setOutputValueClass(NullWritable.class);
  39.  
  40. job.setInputFormatClass(BinaryInputFormat.class);
  41. job.setOutputFormatClass(TextOutputFormat.class);
  42.  
  43. FileInputFormat.addInputPath(job, new Path(args[0]));
  44. FileOutputFormat.setOutputPath(job, new Path(args[1]));
  45.  
  46. System.exit(job.waitForCompletion(true) ? 0 : 1);
  47. }
  48. }
  49.  
  50. class BinaryInputFormat extends FileInputFormat<NullWritable, BytesWritable> {
  51. @Override
  52. public RecordReader<NullWritable, BytesWritable> createRecordReader(InputSplit split, TaskAttemptContext context) {
  53. return new BinaryRecordReader();
  54. }
  55. }
Success #stdin #stdout #stderr 0.01s 5308KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: near line 1: near "import": syntax error
Error: near line 2: near "import": 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 "import": syntax error
Error: near line 13: near "import": syntax error
Error: near line 15: near "public": syntax error
Error: near line 20: unrecognized token: "}"
Error: near line 26: unrecognized token: "}"
Error: near line 31: near "Job": syntax error
Error: near line 32: near "job": syntax error
Error: near line 34: near "job": syntax error
Error: near line 35: near "job": syntax error
Error: near line 37: near "job": syntax error
Error: near line 38: near "job": syntax error
Error: near line 40: near "job": syntax error
Error: near line 41: near "job": syntax error
Error: near line 43: near "FileInputFormat": syntax error
Error: near line 44: near "FileOutputFormat": syntax error
Error: near line 46: near "System": syntax error
Error: near line 47: unrecognized token: "}"
Error: near line 54: unrecognized token: "}"