avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pankaj Shroff <shro...@gmail.com>
Subject Re: Question about Avro "records"
Date Wed, 27 Feb 2013 22:21:04 GMT
Yes thats right, and the default value can be "null" - which is what makes
"b" an "optional" field.

You can define an optional field by defining it of type "union" in an Avro
schema where the first type in the union is "null" and the second type is
"long" or integer in your case.

Something like this (.avsc or .avpr file would have the following Json):

{
    "type": "record",
    "name": "OptionalFieldsExample",
    "fields": [
        {"name": "a",        "type": "long"},
        {"name": "b", "type": ["null", "long"]},
        {"name": "c", "type": ["null", "long"]}

    ]}



On Wed, Feb 27, 2013 at 5:14 PM, Francis Galiegue <fgaliegue@gmail.com>wrote:

> On Wed, Feb 27, 2013 at 10:54 PM, Pankaj Shroff <shroffg@gmail.com> wrote:
> > That doesn't seem the case specially because if you define a record with
> a
> > bunch of optional fields, then you would end up with an empty object (or
> > rather an object with null values for its fields). Am I misunderstanding
> > your question?
> >
>
> OK, I have probably misworded the question. Let's say I have a record
> defining fields "a" and "b". For simplicity, their permissible values
> are ints.
>
> As I understand it:
>
> { "a": 1 }
>
> is not legal since "b" is not provided.
>
> This:
>
> { "a": 1, "b": 2, "c": 3 }
>
> is not legal either since "c" is not defined.
>
> BUT: { "a": 1 } can be legal IF a default value is provided for "b".
>
> Am I getting this right, partially right, completely wrong?
>
> --
> Francis Galiegue, fgaliegue@gmail.com
> JSON Schema in Java: http://json-schema-validator.herokuapp.com
>



-- 
Pankaj Shroff
shroffG@Gmail.com

Mime
View raw message