以WordCount为例,假设已经按正常情况编写了Mapper和Reducer,主程序中job如下设置:
Job job = Job.getInstance(conf,"Word-Count");
job.setJarByClass(WordCountMain.class);
job.setMapperClass(WordCountMapper.class);
job.setReducerClass(WordCountReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
这个时候,运行程序,结果是拍过序的,假设输入数据如下:
hello world
word hello
a word
hello java hello
scala
b
java is scala
最终输出结果如下:
a 1
b 1
hello 4
is 1
java 2
scala 2
word 2
world 1
去除reducer和map的排序,有两种方法:
(1)不设置reducer
去掉代码job.setReducerClass(WordCountReducer.class);
(2)设置reduce task为0
job.setNumReduceTasks(0);