MapReduce使用OutputFormat类将数据输出存入文件中,其基本与InputFormat类似。输出没有分块,每个Reducer将它的输出直接写到自己的文件中。输出文件存在于一个共有目录当中,一般被命名为part-nnnnn,nnnnn是Reducer的分区ID。
Hadoop提供数种标准的OutputFormat的实现,如表中所示。几乎所有我们使用的类都继承自FileOutputFormat。
OutputFormat | Description |
---|---|
TextOutputFormat<K,V>(default) | 一行输出一个记录,Keys和Values为string格式,并且以TAB(\t)字符分隔开,字符可从mapred.textoutputformat.separator属性设置 |
SequenceFileOutputFormat<K,V> | 将<key,value>键值对以Hadoop独有的序列格式输出,与SequenceFileInputFormat同时工作。 |
NullOutputFormat | 什么都不输出。 |
不同的是,我们通过继承FileInputFormat类实现自己的InputFormat类,但我们使用JobConf对象的setOutputFormat来指定OutputFormat。
Note:并不是所有的OutputFormat(InputFormat)都继承自FileOutputFormat(FileInputFormat),我们还有从数据库中读取数据的相关OutputFormat(InputFormat)类。有兴趣的读者可以查看Hadoop API中的DBInputFormat,DBOutputFormat类的文档。