码迷,mamicode.com
首页 > 其他好文 > 详细

hadoop 统计输入的行数的MAP

时间:2015-08-18 19:53:27      阅读:100      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!