1.文件内容如下:
I like aa I like a I like aa
2.Map函数如下:
public static class Map extends Mapper<Object, Text, Text, IntWritable> { private final static IntWritable one = new IntWritable(1); public void map(Object key, Text value, Context context) throws IOException, InterruptedException { String word = value.toString(); String regex = "a*"; Pattern p = Pattern.compile(regex); Matcher m = p.matcher(word); while (m.find()) { String a = m.group(); if(!"".equals(a)) { context.write(new Text(a), one); } } } }
Map函数处理完应该时这样的:<a,1>,<aa,<1, 1>>,可是在调试过程中发现,只能处理文件的第一行,执行完context.write(new Text(a), one);之后会以此执行下图中,然后结束进程。
但是对文件第一行的操作是正确的,成功的提取了"aa"
你是不是,传给map的Text的value就是只传了文件第一行呀
应该没有吧...我是发现运行不成功调试的,我也是调试的时候才发现只处理了一行...其他的MapReduce程序都好好的呀,唯独这个只能处理一行然后就不行了
执行完context.write(new Text(a), one);
下一步到这里了...
你可以在word那打个断点,看下word的值是什么。还有为什么正则不直接用 a+ 啊?