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\" } "
> > "]"
> > "}"