Hadoop之——自定义排序算法实现排序功能

时间:2015-05-31 14:00:03   收藏:0   阅读:299

要求首先按照第一列升序排列,当第一列相同时,第二列升序排列;不多说直接上代码

1、Mapper类的实现

	/**
	 * Mapper类的实现
	 * @author liuyazhuang
	 *
	 */
	static class MyMapper extends Mapper<LongWritable, Text, NewK2, LongWritable>{
		protected void map(LongWritable key, Text value, org.apache.hadoop.mapreduce.Mapper<LongWritable,Text,NewK2,LongWritable>.Context context) throws java.io.IOException ,InterruptedException {
			final String[] splited = value.toString().split("\t");
			final NewK2 k2 = new NewK2(Long.parseLong(splited[0]), Long.parseLong(splited[1]));
			final LongWritable v2 = new LongWritable(Long.parseLong(splited[1]));
			context.write(k2, v2);
		};
	}
2、Reducer类的实现

	/**
	 * Reducer类的实现
	 * @author liuyazhuang
	 *
	 */
	static class MyReducer extends Reducer<NewK2, LongWritable, LongWritable, LongWritable>{
		protected void reduce(NewK2 k2, java.lang.Iterable<LongWritable> v2s, org.apache.hadoop.mapreduce.Reducer<NewK2,LongWritable,LongWritable,LongWritable>.Context context) throws java.io.IOException ,InterruptedException {
			context.write(new LongWritable(k2.first), new LongWritable(k2.second));
		};
	}
3、

原文:http://blog.csdn.net/l1028386804/article/details/46288107

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!