avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vivek Hungund <Vivek.Hung...@Incentica.net>
Subject Union of a record and null in a schema
Date Sat, 16 Apr 2011 02:19:54 GMT
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.profile
s","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.

Mime
View raw message