MapReduce示例代码

  1. /*
  2. * DEMO Map/Reduce class test2
  3. * -- Convert GPDBFormat back to TEXT
  4. */
  5. public static class Map_test2 extends Mapper<LongWritable, GPDBWritable,
  6. Text, NullWritable> {
  7. public void map(LongWritable key, GPDBWritable value, Context context )
  8. throws IOException {
  9. try {
  10. context.write(new Text(value.toString()), NullWritable.get());
  11. } catch (Exception e) { throw new IOException (e.getMessage()); }
  12. }
  13. }
  14. public static void runTest2() throws Exception{
  15. Configuration conf = new Configuration(true);
  16. Job job = new Job(conf, "test2");
  17. job.setJarByClass(demoMR.class);
  18. job.setInputFormatClass(GPDBInputFormat.class);
  19. job.setOutputKeyLClass (Text.class);
  20. job.setOutputValueClass(NullWritable.class);
  21. job.setOutputFormatClass(TextOutputFormat.class);
  22. job.setMapperClass(Map_test2.class);
  23. GPDBInputFormat.setInputPaths (job,
  24. new Path("/demo/data/writeFromGPDB_42"));
  25. GPDBOutputFormat.setOutputPath(job, new Path("/demo/data/MRTest2"));
  26. job.waitForCompletion(true);
  27. }

上级主题: 一次性HDFS协议安装