You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@avro.apache.org by Yang <te...@gmail.com> on 2011/07/28 21:25:37 UTC

how to utilize default?

the schema in http://avro.apache.org/docs/1.5.1/spec.html#schema_record
allows definition of { "default": my_default_value ..... }

but I guess I can't simply access a record field by

my_record_obj.my_field_name

and hope to get the default value , right? but then how can the
default value be obtained?

Thanks
Yang





############ java code
package blah;
public class aaa {
public static void main(String args[]){
MyClass o = new MyClass();
System.out.println(o.my_field);
}
}

############ avdl fle:
@namespace("blah")
protocol MyProto {
    record MyClass {
        long  my_field=1;
    }
    int my_func(MyClass c);
}

Re: how to utilize default?

Posted by Yang <te...@gmail.com>.
thanks Doug and James!
On Jul 28, 2011 1:27 PM, "James Baldassari" <jb...@gmail.com> wrote:
> See also AVRO-839, which I think would give you the behavior you're
looking
> for. I'm hoping to have time to finish up that patch in the next few
weeks,
> if things ever slow down at work for long enough.
>
> -James
>
>
> On Thu, Jul 28, 2011 at 4:20 PM, Doug Cutting <cu...@apache.org> wrote:
>
>> On 07/28/2011 12:25 PM, Yang wrote:
>> > but I guess I can't simply access a record field by
>> >
>> > my_record_obj.my_field_name
>> >
>> > and hope to get the default value , right? but then how can the
>> > default value be obtained?
>>
>> Default values are used when reading a different version of the record
>> that does not contain the field. So if you add a new integer field
>> whose default value is -1, then read a record written before that field
>> was added, the old record will contain -1 as the value for the new
>> field. Implementations might also use the default value to initialize
>> values when creating new record data structures, but that's not required.
>>
>> Doug
>>

Re: how to utilize default?

Posted by James Baldassari <jb...@gmail.com>.
See also AVRO-839, which I think would give you the behavior you're looking
for.  I'm hoping to have time to finish up that patch in the next few weeks,
if things ever slow down at work for long enough.

-James


On Thu, Jul 28, 2011 at 4:20 PM, Doug Cutting <cu...@apache.org> wrote:

> On 07/28/2011 12:25 PM, Yang wrote:
> > but I guess I can't simply access a record field by
> >
> > my_record_obj.my_field_name
> >
> > and hope to get the default value , right? but then how can the
> > default value be obtained?
>
> Default values are used when reading a different version of the record
> that does not contain the field.  So if you add a new integer field
> whose default value is -1, then read a record written before that field
> was added, the old record will contain -1 as the value for the new
> field.  Implementations might also use the default value to initialize
> values when creating new record data structures, but that's not required.
>
> Doug
>

Re: how to utilize default?

Posted by Doug Cutting <cu...@apache.org>.
On 07/28/2011 12:25 PM, Yang wrote:
> but I guess I can't simply access a record field by
> 
> my_record_obj.my_field_name
> 
> and hope to get the default value , right? but then how can the
> default value be obtained?

Default values are used when reading a different version of the record
that does not contain the field.  So if you add a new integer field
whose default value is -1, then read a record written before that field
was added, the old record will contain -1 as the value for the new
field.  Implementations might also use the default value to initialize
values when creating new record data structures, but that's not required.

Doug