Hi Martin, I am tied up the rest of today thank you very much for getting back. I'll write here tomorrow. Thank you Lewis
On Tue, Jan 7, 2014 at 6:41 PM, Martin Kleppmann <[email protected]>wrote: > Hi Lewis, > > In Avro, types are not nullable by default (unlike most programming > languages). So a type of {"type":"map", "values":"string"} with a default > of null does not make sense, because the type can never be null. If you > wanted the type to be nullable, your type would have to be ["null", > {"type":"map", "values":"string"}]. > > But a better solution may be to set your default to {}, like this: > > {"name": "outlinks", "type": {"type":"map", "values":"string"}, > "default":{}} > > Does that help? > Martin > > > On 7 January 2014 10:50, Lewis John Mcgibbney > <[email protected]>wrote: > >> Hi Folks, >> We have the following avsc (below). The problem we are having though is >> that when we want to reach a 'map' type field e.g. outlinks, field value >> comes null (not with an empty map object). To prevent this, we have to set >> an empty map object before we do any operation in order not to get any NPE. >> We therefore have to set empty map objects before any serialization... >> Is there a better default value for this field (and other similar >> scenarios)? >> Thanks in advance, any guidance is greatly appreciated. >> Lewis >> >> { >> "type": "record", >> "name": "WebPage","default":null, >> "namespace": "org.apache.gora.examples.generated", >> "fields" : [ >> {"name": "url", "type": ["null","string"], "default":null}, >> {"name": "content", "type": ["null","bytes"],"default":null}, >> {"name": "parsedContent", "type": {"type":"array", "items": "string"}, >> "default":null}, >> {"name": "outlinks", "type": {"type":"map", "values":"string"}, >> "default":null}, >> {"name": "metadata", "default":null, "type": { >> "name": "Metadata", >> "type": "record", >> "namespace": "org.apache.gora.examples.generated", >> "fields" : [ >> {"name":"version","type":"int","default":0}, >> {"name":"data","type":{"type":"map","values":"string"}, >> "default":null} >> ] >> }} >> ] >> } >> >> >> >> -- >> *Lewis* >> > > -- *Lewis*
