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 >> avro accessing record within an array in C


Copy link to this message
-
Re: avro accessing record within an array in C
Hi,

I can't really help with the datum api since I haven't used it myself, but with newer avro_value api arrays should work like this:

avro_value_iface_t  *iface;
avro_value_t value, array, element, field;
avro_schema_t schema;
avro_schema_error_t error;

avro_schema_from_json(some_schema, strlen(some_schema), &schema, &error);

iface = avro_generic_class_from_schema(schema);
avro_generic_value_new(iface, &value);

avro_value_get_by_name(&value, "some_array", &array, NULL);
avro_value_append(&array, &element,NULL);

avro_value_get_by_name(&element, "array_record_var_1", &field, NULL);
avro_value_set_int(&field,123);

avro_value_get_by_name(&element, "array_record_var_2", &field, NULL);
avro_value_set_boolean(&field,1);

etc.

I didn't try this at all, so there'll be typos and other errors, but hope it helps to find the solution….

-Mika
On Sep 24, 2013, at 6:33 PM, Mahesh V <[EMAIL PROTECTED]> wrote:

> Hi,
>  
> given a schema as shown below, how can I set values
> to the record "array_record_1" in the array below.?
>  
> Any help will be appreciated.
> thanks
> Mahesh
>  
>  avro_schema_t  array_schema = avro_schema_get_subschema(sw_schema, "some_array");
>  array_datum = avro_array(array_schema);
> ^^^^^ this works fine.
>  
>  avro_schema_t array_rec_schema = avro_schema_get_subschema(sw_schema, "array_record_1");
>   array_rec_datum = avro_record(array_rec_schema);
> ^^^^ this fails
>  
> char *some_schema > "{"
> "\"type\":\"record\", \"name\" : \"some_schema\", \"fields\": [ "
> "{ \"name\" : \"some_var_a\" , \"type\" : \"int\" },"
> "{"
> "\"name\" : \"some_ip\", \"type\" : {"
> "\"type\":\"record\", \"name\" : \"some_ip\", \"fields\" : [ "
> " { \"name\" : \"ip_version\", \"type\" : \"int\" },"
> " { \"name\" : \"ip_v4\", \"type\" : \"long\" },"
> " { \"name\" : \"ip_v6\", \"type\" : \"string\" }"
> "]}},"
> "{ \"name\" : \"some_array\" , \"type\" : "
> " { \"type\":\"array\", \"items\": "
> "{"
> "\"type\":\"record\", \"name\" : \"array_record_1\", \"fields\": [ "
> "{ \"name\" : \"array_record_var_1\" , \"type\" : \"int\" },"
> "{ \"name\" : \"array_record_var_2\" , \"type\" : \"boolean\" } "
> "]"
> "}"
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