Hadoopの単語数の例を非分散モードで実行することができました。「part-00000」という名前のファイルで出力を取得します。すべての入力ファイルを組み合わせたすべての単語が一覧表示されていることがわかります。
単語数コードをトレースした後、行を取り、スペースに基づいて単語を分割していることがわかります。
複数のファイルで発生した単語とその発生を一覧表示する方法を考えていますか?これはMap/Reduceで実現できますか?-追加-これらの変更は適切ですか?
//changes in the parameters here
public static class Map extends MapReduceBase implements Mapper<Text, Text, Text, Text> {
// These are the original line; I am not using them but left them here...
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
//My changes are here too
private Text outvalue=new Text();
FileSplit fileSplit = (FileSplit)reporter.getInputSplit();
private String filename = fileSplit.getPath().getName();;
public void map(Text key, Text value, OutputCollector<Text, Text> output, Reporter reporter) throws IOException {
String line = value.toString();
StringTokenizer tokenizer = new StringTokenizer(line);
while (tokenizer.hasMoreTokens()) {
word.set(tokenizer.nextToken());
// And here
outvalue.set(filename);
output.collect(word, outvalue);
}
}
}