我有一個輸入文件包含:Hadoop的 - 輸入的共線文件
id value
1e 1
2e 1
...
2e 1
3e 1
4e 1
而且我想找到我的輸入文件的總ID。因此,在我的主要中,我已經聲明瞭一個列表,以便當我讀取輸入文件時,我會將該行插入列表中
MainDriver.java public static Set list = new HashSet();
和我在我的地圖
// Apply regex to find the id
...
// Insert id to the list
MainDriver.list.add(regex.group(1)); // add 1e, 2e, 3e ...
,並在我的減少,我嘗試使用列表作爲
public void reduce(WritableComparable key, Iterator values,
OutputCollector output, Reporter reporter) throws IOException
{
...
output.collect(key, new IntWritable(MainDriver.list.size()));
}
因此,我希望值打印出來的文件,在這種情況下將4但它實際上打印出0.
我已驗證regex.group(1)會提取有效的ID。所以我不知道爲什麼在reduce過程中我的列表大小爲0。