HDFS Forum

Web App mapreduce job failing

  • #29963
    John Brinnand
    Participant

    I have a mapreduce job which I am executing from a web application. The jobs starts up but it fails with the following well known error:

    java.lang.Exception: java.io.IOException: Type mismatch in key from map: expected org.apache.hadoop.io.Text, recieved org.apache.hadoop.io.LongWritable
    at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:354)
    Caused by: java.io.IOException: Type mismatch in key from map: expected org.apache.hadoop.io.Text, recieved org.apache.hadoop.io.LongWritable
    …………

    I have followed the general advice to fix this problem by setting the output of my map to Text and IntWritiable but it has no effect. I keep getting the same response. Here is the code.

    public class WordCountGamma extends Configured implements Tool {
    public int run(String[] args) throws Exception {
    Configuration conf = new Configuration();
    Job job = new Job(conf, “wordcount”);
    job.setMapperClass(WordCountMapper.class);
    job.setReducerClass(WordCountReducer.class);

    job.setInputFormatClass(TextInputFormat.class);
    job.setOutputFormatClass(TextOutputFormat.class);

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

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

    FileInputFormat.setInputPaths(job, new org.apache.hadoop.fs.Path(args[0]));
    FileOutputFormat.setOutputPath(job, new org.apache.hadoop.fs.Path(args[1]));

    job.waitForCompletion(true);
    return 0;
    }
    }

    public class WordCountMapper extends Mapper {
    private final static IntWritable one = new IntWritable(1);
    private Text word = new Text();

    public void map(Object key, Text value,
    OutputCollector output, Reporter reporter) throws IOException {
    String line = value.toString();
    StringTokenizer tokenizer = new StringTokenizer(line);
    while (tokenizer.hasMoreTokens()) {
    word.set(tokenizer.nextToken());
    output.collect(word, one);
    }
    }
    }
    public class WordCountReducer extends Reducer {
    public void reduce(Text key, Iterator values,
    OutputCollector output, Reporter reporter) throws IOException {
    int sum = 0;
    while (values.hasNext()) {
    sum += values.next().get();
    }
    output.collect(key, new IntWritable(sum));
    }
    }

    I am using hadoop-core-1.2.0 and running on Hortonworks VM. What am I missing?

    Thanks,

    John

to create new topics or reply. | New User Registration

  • Author
    Replies
  • #29964
    John Brinnand
    Participant

    Okay – folks. I found the error. It was a library incompatibility. This issue is resolved.

    #29968
    tedr
    Moderator

    Hi John,

    thanks for letting us know that you found and fixed the issue.

    Ted.

The topic ‘Web App mapreduce job failing’ is closed to new replies.

Support from the Experts

A HDP Support Subscription connects you experts with deep experience running Apache Hadoop in production, at-scale on the most demanding workloads.

Enterprise Support »

Become HDP Certified

Real world training designed by the core architects of Hadoop. Scenario-based training courses are available in-classroom or online from anywhere in the world

Training »

Hortonworks Data Platform
The Hortonworks Data Platform is a 100% open source distribution of Apache Hadoop that is truly enterprise grade having been built, tested and hardened with enterprise rigor.
Get started with Sandbox
Hortonworks Sandbox is a self-contained virtual machine with Apache Hadoop pre-configured alongside a set of hands-on, step-by-step Hadoop tutorials.
Modern Data Architecture
Tackle the challenges of big data. Hadoop integrates with existing EDW, RDBMS and MPP systems to deliver lower cost, higher capacity infrastructure.