Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8321023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:52:28+00:00 2026-06-08T22:52:28+00:00

My Map class is public static class MapClass extends Mapper<LongWritable, Text, Text, LongWritable> {

  • 0

My Map class is

 public static class MapClass extends Mapper<LongWritable, Text, Text, LongWritable> {

        public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
            // your map code goes here
            String[] fields = value.toString().split(",");
            String year = fields[1];
            String claims = fields[8];

            if (claims.length() > 0 && (!claims.startsWith("\""))) {
                context.write(new Text(year), new LongWritable(Long.parseLong(claims)));
            }
        }
    }

My Reduce class Looks like

   public static class Reduce extends Reducer<Text, LongWritable, Text, Text> {


        public void reduce(Text key, Iterable<LongWritable> values, Context context) throws IOException, InterruptedException {
            // your reduce function goes here
            context.write(key, new Text("hello"));
        }
    }

The dataset looks like

3070801,1963,1096,,"BE","",,1,,269,6,69,,1,,0,,,,,,,
3070802,1963,1096,,"US","TX",,1,,2,6,63,,0,,,,,,,,, 

When I run program with configuration

        Job job = new Job();
        job.setJarByClass(TopKRecords.class);

        job.setMapperClass(MapClass.class);
        job.setReducerClass(Reduce.class);

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

        job.setJobName("TopKRecords");
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(Text.class);

I see error as

java.io.IOException: Type mismatch in value from map: expected org.apache.hadoop.io.Text, recieved org.apache.hadoop.io.LongWritable
    at org.apache.hadoop.mapred.MapTask$MapOutputBuffer.collect(MapTask.java:1019)
    at org.apache.hadoop.mapred.MapTask$NewOutputCollector.write(MapTask.java:691)
    at org.apache.hadoop.mapreduce.TaskInputOutputContext.write(TaskInputOutputContext.java:80)
    at com.hadoop.programs.TopKRecords$MapClass.map(TopKRecords.java:35)
    at com.hadoop.programs.TopKRecords$MapClass.map(TopKRecords.java:26)
    at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:144)
    at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:764)
    at org.apache.hadoop.mapred.MapTask.run(MapTask.java:370)
    at org.apache.hadoop.mapred.Child$4.run(Child.java:255)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:396)
    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1121)
    at org.apache.hadoop.mapred.Child.main(Child.java:249)

What is wrong going here?

I dont see any reason for mismatch here

Mapper<LongWritable, Text, Text, LongWritable>
Reducer<Text, LongWritable, Text, Text>

UPDATE

After setting the following, things started to work

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(LongWritable.class);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T22:52:29+00:00Added an answer on June 8, 2026 at 10:52 pm

    You also need the following line during your setup:

    job.setMapOutputValueClass(LongWritable.class);
    

    From the Hadoop 20.2 Javadoc:

    This allows the user to specify the map output value class to be
    different than the final output value class.

    For clarity, you could also add:

    job.setMapOutputKeyClass(Text.class);
    

    but it is not necessary in this case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public static class MapClass extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> { private Text
public static class Map extends MapReduceBase implements Mapper MapReduceBase , Mapper and JobConf are
import java.util.HashMap; import java.util.Map; public class Main { public static void main(String[] args) {
import java.io.*; import java.util.*; public class Sort { public static void main(String[] args) throws
in Combinator class: public static <KEY, T> void getCombsIntoTreeMap(int N, int K, TreeMap<KEY, T>
public ref class ScriptEditor : public Form { public: typedef map<UInt32, ScriptEditor^> AlMap; static
Assume I have a class like this: public class Server { public static void
Here is my GeneratePdf.java Import ... public class GeneratePdf { public static void main(String[]
I have the following code public class Test{ private static final String key =
import java.util.*; public class HashMapExample { public static class WriteOnceMap<K, V> extends HashMap<K, V>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.