最近、Hadoopを学び始めました。ここで、ローカルディスクのファイルを開き、reduce関数でそのファイルにデータを書き込みたいのですが、そのファイルを閉じるための適切な方法が見つかりませんでした。
私の知る限り、それを閉じて再び開くのは良い考えではないので、私はそれをしたくありません。
public class MyClass extends Configured implements Tool{
main(){
//all configurations here
job.setMapperClass(MyMapper.class);
job.setReducerClass(MyReducer.class);
}
static class MyMapper extends Mapper <LongWritable,Text,Text,Text>{
//does something
}
static class MyReducer extends Reducer <LongWritable,Text,Text,Text>{
//create file, filewriter etc here
public MyReducer() {
//open a file here
}
public reduce(){
//write to file here
bw.write("entered the reduce task for " + key);
while(there is more item)
bw.write( value + " will be written to my file \n");
}
}
}
ワークフローは次のようになります(間違っている場合は修正してください)。
for(each reduce task)
write to file "entered the reduce task for " + *key*
for each *value* for that *key*
write *value*
ローカルディスクに書き込まれたmyfileにキーと値のペアを書き込み、ファイルを閉じたいのですが、その問題の適切な解決策が見つかりません。それとも、ファイルを閉じないと、問題になりますか?つまり、Hadoopがそれを処理しているのでしょうか?
ありがとう、