1
我最近開始學習hadoop。現在,我想在本地磁盤中打開一個文件,並在reduce函數中將一些數據寫入該文件,但我無法找到關閉該文件的好方法。hadoop關閉文件寫在本地磁盤上
據我所知,關閉並重新打開它不是一個好主意,所以我不想這樣做。
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正在處理這個問題,這會是一個問題嗎?
感謝,