私は非分散モードでHadoopのワードカウントの例を実行することができました。私は "part-00000"という名前のファイルに出力します。私はそれがすべての入力ファイルのすべての単語を組み合わせてリストすることがわかります。ファイル数Wordcount一般的な単語
ワードカウントコードをトレースした後、私はそれが行を取り、スペースに基づいて単語を分割することがわかります。
私は、複数のファイルに出現した単語とその出現をリストする方法を考えようとしていますか?これはMap/Reduceで達成できますか? -Added- これらの変更は適切ですか?
//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);
}
}
}
はあなたにクリスありがとう...それを行う方法に私を導いていただけますか?私はワードカウントマップクラスに次の行を追加しました: \t \t \t FileSplit fileSplit =(FileSplit)reporter.getInputSplit(); \t \t \tプライベート文字列ファイル名= fileSplit.getPath()。getName();; \t \t \t output.collectの中のwhileループの中で次のもの(word、filename)。 \t 私はこれまでに何をしていますか?現在の単語を現在のファイルにするための最初のステップとして... – ibininja
私は現在、Hadoopを使用しています。0.20.2 – ibininja
私にはいい音です。見てみましょう(FYI、0.20.2を使っていても、まだ運動しています古いAPI) –