在 map reduce word count 程序中需要获取单词存在的文件

In a map reduce word count program need to fetch the files where the words exist

我正在读取多个输入文件以解决字数统计问题。

示例文件名: file1.txt file2.txt file3.txt

我能够获取字数,但如果我还想获取文件名以及字数,应该添加什么。

举个例子,

文件 1 的内容:欢迎使用 Hadoop

文件 2 的内容:这是 hadoop

当前输出:

Hadoop 2

是1

这1

到 1

欢迎 1

预期输出:

Hadoop 2 File01.txt File02.txt

是 1 File02.txt

这1个File02.txt

至 1 File01.txt

欢迎 1 File01.txt

第一次做输入分割 String file = ((FileSplit)inputSplit).getPath().getName(); 并从映射器中收集单词和文件名作为输出。

在reducer中,根据键计算文件名并增加计数器并继续附加文件名。

   file += filename;
   textString = counter + file;
   output.collect(key,new Text(textString));

这解决了问题。