It's hard to tell what's wrong without a complete program and a stack
trace, but I believe this error message is from the GenericData.Record()
constructor. When you construct an instance of this you must pass in a
record schema, not the union schema.
Doug
On 04/15/2011 07:19 PM, Vivek Hungund wrote:
> Hi,
>
> I’m trying to figure out how to make the location field in the following
> schema a union of a record and null, similar to the way hometown is a
> union of a string and null.
>
> {
> "name" : "Profile",
> "type" : "record",
> "fields" : [
> { "name" : "name", "type" : "string" },
> { "name" : "location", "type" : {
> "type" : "record",
> "name" :
> "cityState",
> "fields" : [
> {
> "name"
> : "city", "type" : [ "string" , "null" ] },
> {
> "name"
> : "state", "type" : [ "string", "null" ] }
> ]
> }
> },
> { "name" : "hometown", "type" : [ "string", "null" ] }
> ]
> }
>
> However, if I follow the pattern and make it:
>
> { "name" : "location", "type" : [ {
> "type" : "record",
> "name" :
> "cityState",
> "fields" : [
> {
> "name"
> : "city", "type" : [ "string" , "null" ] },
> {
> "name"
> : "state", "type" : [ "string", "null" ] }
> ]
> }, “null” ]
> },
>
>
> I get the following error
>
> _org.apache.avro.AvroRuntimeException_: Not a record schema:
> [{"type":"record","name":"cityState","namespace":"com.incentica.avro.profiles","fields":[{"name":"city","type":["string","null"]},{"name":"state","type":["string","null"]}]},"null"].message}
>
> From what I read in the specification, this should be allowed. Is my
> syntax incorrect?
>
> Thanks.