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 Plain View
Avro >> mail # user >> avro accessing record within an array in C


+
Mahesh V 2013-09-24, 15:33
+
Mika Ristimaki 2013-09-24, 19:13
+
Mahesh V 2013-09-25, 08:18
+
Mika Ristimaki 2013-09-25, 09:16
+
Mahesh V 2013-09-25, 10:18
Copy link to this message
-
Re: avro accessing record within an array in C
Quick question.
How do I read the schema of an empty array?

for e.g if my schema look like whats shown below, then given a fieldname
e.g. array_record_var_1,
how do I check if the field exists inside the array , even if the array is
empty.

the below snippet of code works fine if the array has at least one element.
if the array is not populated, the avro_value_get_size returns 0 and the
code does not enter the for loop

 if(type == AVRO_ARRAY ) {
                avro_value_get_size(&field, &array_count);
                printf(" array number of elements = %d \n", array_count);
                for(j = 0; j < array_count; j++) {
                    avro_value_get_by_index(&field, j, &subfield, &name),
                    printf(" field name is : %s , type =", name);
                    type = avro_value_get_type(&subfield);
                    print_type(type);
                    printf("\n");
                    if(type == AVRO_RECORD) {
                        avro_value_get_size(&subfield, &rec_count);
                        printf(" record number of elements = %d \n",
rec_count);
                        for(k = 0; k < rec_count; k++) {
                            avro_value_get_by_index(&subfield, k, &subrec,
&name),
                            printf(" field name is : %s , type =", name);
                            type = avro_value_get_type(&subrec);
                            print_type(type);
                            printf("\n");
                        }
                    }
                }
            }

> > 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\" } "
> > "]"
> > "}"
+
Mika Ristimaki 2013-09-26, 08:23
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