mapreduce主要的实现需要三个类:主方法类、map类、reduce类。
1. 主方法类:
public class BreadPointDriver {
/**
*
* @param args
* @throws IOException
* @throws ClassNotFoundException
* @throws InterruptedException
*/
public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
//配置项
Configuration conf = new Configuration();
//定义任务,第一个参数设定配置项,第二个参数设置任务名称
Job job = new Job(conf, "bscreenUserCount");
//设置输入文件格式化类
job.setInputFormatClass(FileInputFormat.class);
//设置输出文件格式化类
job.setOutputFormatClass(FileOutputFormat.class);
//设置启动类
job.setJarByClass(BreadPointDriver.class);
//设置mapper
job.setMapperClass(UserCountMapper.class);
//设置reducer
job.setReducerClass(UserCountReducer.class);
//设置reducer数量, 如果不设置默认为1,如果设置0则不执行reducer,设置1以上需要编写partition类
job.setNumReduceTasks(0);
job.setMapOutputKeyClass(Text.class);//map输