JOB2:对job1的输出进行二次排序,按值从大到小排序 SortSecond.java
package com.bazhangkeji.hadoop2; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; import org.apache.hadoop.util.GenericOptionsParser; public class SortSecond { public static void main(String[] args) throws Exception { Configuration conf = new Configuration(); String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs(); if (otherArgs.length != 2) { System.err.println("Usage: csdndata <in> <out>"); System.exit(2); } Job job = new Job(conf, "sortsecond"); job.setJarByClass(SortSecond.class); job.setMapperClass(MapSecond.class); job.setReducerClass(ReduceSecond.class); job.setSortComparatorClass(SortMy.class); //设置自定义二次排序策略 job.setOutputKeyClass(KeyMy.class); job.setOutputValueClass(IntWritable.class); FileInputFormat.addInputPath(job, new Path(otherArgs[0])); FileOutputFormat.setOutputPath(job, new Path(otherArgs[1])); System.exit(job.waitForCompletion(true) ? 0 : 1); } }
|