0

各 Reducer がその値 (またはキー) として整数を出力すると仮定します。Hadoop のメイン プログラムでこれらの値 (またはキー) にアクセスする (たとえば、それらを合計する) 方法はありますか?

4

1 に答える 1

2

あなたの出力形式は何ですか?SequenceFileOutput を使用している場合は、SequenceFile.Reader クラスを使用して、ジョブの完了後にメイン プログラムで part-r-xxxxx ファイルを開くことができます。たとえば、 を出力するジョブ<Text, IntWritable>の場合、次のように値を合計できます。

FileSystem fs = FileSystem.get(getConf());
Text key = new Text();
IntWritable value = new IntWritable();
long total = 0;
for (FileStatus fileStat : fs.globStatus(new Path("/user/jsmith/output/part-r-*"))) {
  SequenceFile.Reader reader = new SequenceFile.Reader(fs, fileStat.getPath(), getConf());
  while (reader.next(key, value)) {
    total = value.get();
  }
  reader.close();
}

TextOutputFormat の場合、おそらく次のようになります (for ループの内容を置き換えます)。

BufferedReader reader = new BufferedReader(new InputStreamReader(fs.open(fileStat.getPath())));
String nextLine;
while ((nextLine = reader.readLine()) != null) {
  String tokens[] = nextLine.split("\t");
  total += Integer.parseInt(tokens[1]);
}
reader.close();
于 2013-01-17T00:24:00.180 に答える