首页 > 代码库 > mapreduce-combiner函数使用例子代码

mapreduce-combiner函数使用例子代码



import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;


import com.MaxTemperatureMapper;
import com.MaxTemperatureReducer;
import com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider.Text;


//本程序是使用combiner函数的例子
//
public class MaxTemperatureWithCombiner {


/**
* @param args
*/
public static void main(String[] args) throws Exception{
// TODO Auto-generated method stub
if(args.length != 2){
System.out.println("Usage: MaxTemperatureWithCombiner输入路径" + "输出路径");
System.exit(-1);
}

Job job = new Job();
job.setJarByClass(MaxTemperatureWithCombiner.class);
job.setJobName("Max temperature");

FileInputFormat.addInputPath(job, new Path(""));
FileOutputFormat.setOutputPath(job, new Path(""));

job.setMapperClass(MaxTemperatureMapper.class);
job.setCombinerClass(MaxTemperatureReducer.class);
job.setReducerClass(MaxTemperatureReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
job.setOutputValueClass(IntWritable.class);

System.out.println(job.waitForCompletion(true) ? 0 : 1);

}


}

mapreduce-combiner函数使用例子代码