2
我有一個mapreduce程序,其輸出全部在文本文件中。該程序的一個示例如下。 我不知道該怎麼做,是從reducer輸出序列文件格式的鍵/值對。 不,我不能因爲我使用Hadoop的0.20庫在Hadoop中以順序文件格式寫/讀鍵/值對。
所以,我該怎麼辦使用SequeceFileFormat符?以下是樣本 wordcount程序只是我的大型程序的一小部分。如果我知道如何做到這一點,我可以和其他人一起做。 請幫忙。 字數減速
public void reduce(Text key, Iterable<IntWritable> values, Context context)
throws IOException, InterruptedException
{
int sum = 0;
for (IntWritable val : values) {
sum += val.get();
}
System.out.println("reducer.output: "+key.toString()+" "+sum);
context.write(key, new IntWritable(sum)); **//RIGHT HERE!! OUTPUTS TO TEXT**
}
}
現在,這裏是運行這個(我離開了映射器和其他不相關的細節)
Configuration conf = new Configuration();
Job job = new Job(conf, "Terms");
job.setJarByClass(wordCount.class);
//Outputting key value pairs as a dictionary (rememb python)
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
//Setting the mapper and reducer classes
job.setMapperClass(Map.class);
job.setReducerClass(Reduce.class);
//Setting the type of input format. In this case, plain TEXT
job.setInputFormatClass(TextInputFormat.class);
job.setOutputFormatClass(TextOutputFormat.class);
我知道如何轉換的主程序將文本文件轉換爲序列文件。我知道如何去做相反的事情。這不是問題。我找不到在hadoop程序中實際執行此操作的任何示例,這就是爲什麼我卡住了。
所以輸出,我想這個程序寫的鍵/值對序列中的文件,而不是一個文本文件
我也想知道如何與一個序列讀取文件Mapper
任何幫助將不勝感激。