首页 > 其他 > 详细

hadoop 统计输入的行数的MAP

时间:2015-08-18 19:51:22      阅读:288      评论:0      收藏:0      [点我收藏+]
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

public class FilterCidMap2 extends Mapper<LongWritable, Text, Text, LongWritable> {
	private long count=0;
	@Override
	protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, LongWritable>.Context context)
			throws IOException, InterruptedException {

		try {
		           //取得读取的行数
		         count=key.get();
			
		         //正常逻辑
				context.write(new Text(), new LongWritable(1));

		} catch (Exception e) {

			e.printStackTrace();
		}

	}
	
	//map 方法调用完后才调用的
	@Override
	protected void cleanup(Mapper<LongWritable, Text, Text, LongWritable>.Context context)
			throws IOException, InterruptedException {
		//map清理资源的操作
		//在reduce中把linescount取出来就行了
		context.write(new Text("linesCount"), new LongWritable(count));
	}

}


hadoop 统计输入的行数的MAP

原文:http://my.oschina.net/chiyong/blog/494120

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!