Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Plain View
Avro, mail # user - How to set 'values' in a record


+
Milind Vaidya 2013-04-06, 14:33
+
Douglas Creager 2013-04-08, 13:22
Copy link to this message
-
Re: How to set 'values' in a record
Milind Vaidya 2013-04-08, 13:28
Thanks Doug.

I figured that out over the week end and was able to serialize the data.

I am still struggling with  the issue mentioned in another thread named
"avro_value_t or avro_datum_t". I am not able to read the data using value
API.
On Mon, Apr 8, 2013 at 8:22 AM, Douglas Creager <[EMAIL PROTECTED]>wrote:

> > As the example on the avro c website shows,
> >
> > Create datum for record
> >  avro_datum_t person = avro_record(person_schema);
> >
> >
> > Create Datun for a field
> >  avro_datum_t id_datum = avro_int64(++id);
> >
> > Set the field value in the record
> > avro_record_set(person, "ID", id_datum)
> >
> > With the above API being deprecated,
> >
>
> > How do I set avro_value_t in a record ?
> >
> > I tried searching for counterpart ofavro_value_get_by_name
> > but could not find it
>
> With the old datum API, you had to create a new datum instance for the
> field's value, and then assign that field datum to the record datum
> (just like you did).  With the value API, the record value is
> responsible for creating and managing its fields.  So you use
> avro_value_get_by_name to retrieve the field, regardless of whether
> you're going to read from that field or write into it.  So the value
> equivalent of your example is:
>
>   avro_schema_t  person_schema;
>   avro_value_iface_t  *person_iface;
>   avro_value_t  person;
>   avro_value_t  field;
>
>   // Create value for record
>   person_iface = avro_generic_class_from_schema(person_schema);
>   avro_generic_value_new(person_iface, &person);
>
>   // Set field value in record
>   avro_value_get_by_name(&person, "ID", &field, NULL);
>   avro_value_set_long(&field, ++id);
>
> cheers
> –doug
>
>