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

Switch to Plain View
Avro >> mail # user >> org.apache.avro.file.DataFileWriter$AppendWriteException: java.lang.ClassCastException: org.apache.avro.generic.GenericData$Record cannot be cast to java.util.Map


+
AnilKumar B 2014-02-07, 12:41
Copy link to this message
-
Re: org.apache.avro.file.DataFileWriter$AppendWriteException: java.lang.ClassCastException: org.apache.avro.generic.GenericData$Record cannot be cast to java.util.Map
Hello Anil,

Your eventSchema is a record that carries a single Map type field named "Event".
Your sessionSchema is a record that carries a Map type field "Common"
and an array of _Maps_ called "Event".

What your writer is assuming instead is that the sessionSchema carries
an array of _eventSchema_ records. Therefore, in expecting a map data
type when writing the array, it gets a record data type and throws
"Record cannot be cast to java.util.Map"

Does this help you understand the error?

If you want to instead write an array of eventSchema records (as you
are apparently doing in your code), you should alter your
sessionSchema to inline the eventSchema record schema as the array's
contained data type, such as the below:

{"namespace": "ci.avro",
    "type": "record",
    "name": "Session",
    "fields": [
    {"name":"Common", "type": {"type": "map", "values":"string"}},
    {"name":"events",
        "type": {
            "type": "array",
            "items":{
                "type": "record",
                "namespace": "ci.avro",
                "name": "AvroEvent",
                "fields": [
                {"name":"Event",
                    "type": {
                        "type": "map", "values":"string"
                    }
                }
                ]
            }
        }
    }
    ]
}

On Fri, Feb 7, 2014 at 6:11 PM, AnilKumar B <[EMAIL PROTECTED]> wrote:

Harsh J

 
+
AnilKumar B 2014-02-09, 11:27
+
AnilKumar B 2014-02-07, 12:58