user1336866
user1336866

Reputation:

MapReduce with Hadoop: Type mismatch in key from map

I'm running a simple wordcount program, and I get the following error:

Type mismatch in key from map: expected org.apache.hadoop.io.Text, received org.apache.hadoop.io.LongWritable

What is the meaning of this, and how do I rectify it??

Upvotes: 1

Views: 1092

Answers (3)

Tariq
Tariq

Reputation: 34184

This may happen if you are using TextInputFormat as you input format class..It generates keys of type LongWritable and values of type Text..But maybe your application expects keys of type Text..That's why when you set MapOutputKeyClass explicitly as indicated by shailesh using "job.setMapOutputKeyClass(Text.class)" it works for you.

Upvotes: 0

JHS
JHS

Reputation: 7871

You are giving an input of a sequence file which has LongWritable as the key where as the expected sequence file should have the key as Text.

Upvotes: 0

Chaos
Chaos

Reputation: 11721

You can use either of the following lines in your main function:

 conf.setMapOutputKeyClass(Text.class);
 conf.setMapOutputValueClass(IntWritable.class);

assuming you're using JobConf conf;

OR

    job.setMapOutputKeyClass(Text.class);
    job.setMapOutputValueClass(IntWritable.class);

assuming you're using Job job = new Job();

Upvotes: 4

Related Questions