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

  • SEARCH
  • Home
  • 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 8118887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:38:00+00:00 2026-06-06T04:38:00+00:00

I have a mapper whose output value is set to be an interface like

  • 0

I have a mapper whose output value is set to be an interface like this:

public interface OutValue extends Writable {}

During mapping, I create objects with this signature and emit them:

public class OutRecord implements OutValue {}

My Mapper is like this:

public class ExampleMapper extends
    Mapper<LongWritable, Text, ExampleKey, OutValue > {}

However I am getting this error:

java.io.IOException: Type mismatch in value from map: expected OutValue, recieved OutRecord
    at org.apache.hadoop.mapred.MapTask$MapOutputBuffer.collect(MapTask.java:850)
    at org.apache.hadoop.mapred.MapTask$NewOutputCollector.write(MapTask.java:541)
    at org.apache.hadoop.mapreduce.TaskInputOutputContext.write(TaskInputOutputContext.java:80)

So my first instinct was to try to cast it like this:

context.write(key, (OutValue) record);

However I still get the same error. This worked prior to me changing the mapper output type from the OutRecord class to the OutValue interface. My reason for doing so is that I have many types of OutRecord classes I’d like to emit from this mapper.

Is this possible? Does OutValue have to be a class instead of an interface?

Update:

I dug through some of the source for Hadoop 0.20.205.0 and I found this:

public synchronized void collect(K key, V value, int partition) throws IOException {
...
if (value.getClass() != valClass) {
  throw new IOException("Type mismatch in value from map: expected "
                        + valClass.getName() + ", recieved "
                        + value.getClass().getName());
}

So the runtime checks they are using require strict equality in the class, they do no checking for subclassing / interfaces, etc. Surely this is a common usecase, has anyone tried to do this?

  • 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-06T04:38:03+00:00Added an answer on June 6, 2026 at 4:38 am

    There are a few reasons for this strict checking of types:

    If you’re outputting to a sequence files, the header of this file contains the types of the Key and Value class. Hadoop then uses the registered serializer to create new instances of these objects when the sequence file is read back in.

    If the classes you register as the output types are interfaces, or the actual objects you output are sub-classes of the declared type, than either you will not be able to instantiate the interface at runtime, or the instantiated class will not be the sub class you are expecting (and your deserialization will most probably fail with an IOException).

    (when i started typing this i had another reason in mind but it has escaped me for the time being).

    Now if you want to be able to output different types (subclasses) then look into using the GenericWritable to ‘wrap’ your objects – in this case each object output is preceeded by a type – look at the source and javadocs for more details.

    Be warned, that this comes at some cost – input and output will not utilize the object re-use seen elsewhere in hadoop, but you may not notice this cost. You can re-write GenericWritable to be more efficient by pooling an object for each instance type seen and re-using it in the usual way.

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

Sidebar

Related Questions

I have a number of mappers that look like this: mapper(Photo,photo_table, properties = {
I have a mapper whose output is mapped to multiple different reducer instances by
I have this mapper defined: mapper(Resource, resource_table, properties = {'type' : relation(ResourceType,lazy = False),
I have the following class structure public class Outer{ private Mapper a; .... private
I have a document with a structure like this: Product (root) Document1 (embedded) Document2
I have a Struts + Velocity structure like for example, a Person class, whose
I have an IQueryable whose Entity Framework 4 objects I would like to project
We have tried it using an orm mapper tool, but it opens en closes
I have a select defined in mapper.xml file: <mapper namespace=foo> <select id=selectWithRoles parameterType=String resultMap=personWithRoles>
I have implemented the Data Mapper pattern with the Identity Map pattern. In short:

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.