0

我写了一个小地图程序来阅读日志文件并寻找一个叫做“提取”的词。仅当找到该单词时,它才应将该行写入上下文对象。但不知何故,我看到了输出文件中的所有行。这是我的代码

        public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String line = value.toString();
        StringTokenizer tokenizer = new StringTokenizer(line);
        while (tokenizer.hasMoreTokens()) {
            word.set(tokenizer.nextToken());
            if(word.find("extract") >= -1) {
                context.write(word, null);
            }
        }
    }

你能告诉我我做错了什么吗?谢谢,阿蒂

4

1 回答 1

1

如果您想将该行写入上下文;这是代码模板

public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {

    String line = value.toString();

    if (line.contains("extract")) {
         context.write(value,null);
    }

}
于 2013-04-22T13:28:12.943 回答