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 >>


Hi Martin,
Yes this is a much better solution.
The creation of Dirtyable structures like Map's and Array's means that we
avoid NPE from Avro side so thank you for the suggestion.
Best
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*
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