如何配置hadoop的映射器,使其占用<text,intwritable>

时间:2016-10-24 05:17:05

标签: java hadoop mapreduce

我正在使用两个映射器和两个reducer 。我收到以下错误:

  

java.lang。 ClassCastException :org.apache.hadoop.io。 LongWritable无法转换为 org.apache.hadoop.io。文字

这是因为第一个缩减器写了 <Text, IntWritable> ,而我的第二个映射器正在 <Text,IntWritable> 但是,正如我读到的那样,映射器默认情况下点击<LongWritable, Text>

所以,我必须设置输入格式,如:

job2.setInputFormatClass(MyInputFormat.class);

有没有办法将InputFormat类设置为接收<Text,IntWritable>

2 个答案:

答案 0 :(得分:2)

您不需要自己的输入格式。您只需为第一个作业设置SequenceFileOutputFormat,为第二个作业设置SequenceFileInputFormat。

TextInputFormat使用LongWritable键和Text值,但SequenceFileInputFormat使用您用于存储输出的任何类型。

答案 1 :(得分:2)

映射器的输入类型由您怀疑的InputFormat设置。

通常,当您像这样将工作链接在一起时,最好使用SequenceFileOutputFormat并在下一个工作中SequenceFileInputFormat。这样就可以为您处理类型,并将类型设置为相同,即映射器输入与先前的reducers输出相同。