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)); } }
时间: 2025-01-04 08:47:23