2011年3月11日金曜日

hadoop side effect file

hadoopではファイルを正式なアウトプットの他に作ることができる。 getWorkOutputPath を使う。ディレクトリは正式なアウトプットの出力先と同じなので注意。
 public static class R1 extends
 Reducer {
  public void reduce(Text key, Iterable values,
  Context context) throws IOException, InterruptedException {
   context.write(key, values.iterator().next());
   Path path = FileOutputFormat.getWorkOutputPath(context); 
   Path fpath = new Path(path, "sidefile" + key.toString());  
    OutputStream os = fpath.getFileSystem(context.getConfiguration()).create(fpath);
   PrintWriter pw = new PrintWriter(new OutputStreamWriter(os));
   pw.println("hello");
   pw.flush();
   pw.close();
   os.close();
  }
 }

0 件のコメント: