Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Plain View
Avro >> mail # user >> Getting ClassCastException while using GenericRecord in Mapper


Copy link to this message
-
Getting ClassCastException while using GenericRecord in Mapper
Hi,

I have a simple schema say:

{
    "namespace": "example.proto",
    "name": "Message", "type": "record",
    "fields": [
          {"name": "user",   "type": ["string","null"]}
    ]
}

When I am running map reduce with following mapper :
  public static class IdentityAvroMapper extends  AvroMapper<GenericRecord,
Pair<GenericRecord, GenericRecord>> {
        public void map(GenericRecord text,
                AvroCollector<Pair<GenericRecord, GenericRecord>>
collector, Reporter reporter) throws IOException {
            collector.collect(new Pair<GenericRecord, GenericRecord>(text,
text));
        }
    }

It throws me error "java.lang.ClassCastException: example.proto.Message
cannot be cast to org.apache.avro.generic.GenericRecord"
It works fine if I use Message (generated class) in place of GenericRecord.

So, if I do not wish to use generated code, why am I not able to cast it to
GenericRecord. I want to be able to use map reduce with generic apis. Any
pointers please ?
Regards
Pratyush Chandra
+
Pratyush Chandra 2013-01-14, 13:33
+
Terry Healy 2013-01-14, 19:07