2014-09-25 29 views
0

在Java中的单一类MapReduce作业中,是否必须设置输出键类或值类,或者它是可选的,并且如果未设置,则会应用某种默认设置?例如,如果我在我的工作中注释以下内容,它似乎运行良好,但我只是想确认我没有错过任何东西。在Hadoop作业中,输出密钥类或值类是必需的还是可选的?

线有问题注释掉...

//job.setOutputKeyClass(Text.class); 
//job.setOutputValueClass(IntWritable.class); 

的样本数据文件,我分裂的逗号和第一的最后一列拉...

600000US00601,00601,"00601 5-Digit ZCTA; 006 3-Digit ZCTA",11102 
8600000US00602,00602,"00602 5-Digit ZCTA; 006 3-Digit ZCTA",12869 
8600000US00603,00603,"00603 5-Digit ZCTA; 006 3-Digit ZCTA",12423 
8600000US00604,00604,"00604 5-Digit ZCTA; 006 3-Digit ZCTA",33548 
+0

可能的重复[为什么我们需要在Hadoop程序中显式设置输出键/值类?](http://stackoverflow.com/questions/7461249/why-do-we-need-to-set -the-output-key-value-class-explicit-in-the-the-hadoop-progra) – vefthym 2014-09-25 12:09:56

回答

2

从Hadoop的权威性引导[埃德第三/ CH 7.3]:

Text Output 
The default output format, TextOutputFormat, writes records as lines of text. Its keys 
and values may be of any type, since TextOutputFormat turns them to strings by calling 
toString() on them. Each key-value pair is separated by a tab character, although that 
may be changed using the mapred.textoutputformat.separator property. 

它指出TextOutputFormat呼叫toString()上在输出时都输入密钥&,因此可以接受任何类型。所以我认为它不会在运行简单的MR作业时不会产生任何问题,而不会指定您提到的行。

但是,如果明确指定另一种输出格式,例如SimpleDBOutpFormat,它肯定会产生问题。

+0

+ toString()'方法的+1点。 – vefthym 2014-09-25 12:36:06

相关问题