Home | About | Sematext search-lucene.com search-hadoop.com
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB
 Search Hadoop and all its subprojects:

Switch to Threaded 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
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB