Hello,
I am looking at using the Avro C Library API for a project and was wondering
why Record Fields are not first class "objects"? Meaning, there is not an
AVRO_FIELD type for them. Looking at the python and Java implementations there
is a Field Class in both languages that can be accessed and utilized. However,
in the C implementation there is an avro_schema_field_t but the index and name
attributes are sort of useless (except for hashing) and the type is always
returned. Additionally, all the interfaces for accessing a field are done via
avro_schema_record_field_*.
I was looking to try and add some default value support for the project I am
working on but am finding that without the ability to return an AVRO_FIELD type
that the interfaces get ugly very quickly.
avro_value_t avro_schema_record_field_get_default_by_index(rSchema, i);
avro_value_t avro_schema_record_field_get_default_by_name(rSchema,
"field1");
int avro_schema_record_field_set_default_by_index(rSchema, i, value);
int avro_schema_record_field_set_default_by_name(rSchema, "field1", value);
Additionally, if we wanted to add any other attributes from the Specification
("doc", "order", "aliases") then the same very long API call names persist.
char * avro_schema_record_field_get_doc_by_index(rSchema, i);
char * avro_schema_record_field_get_doc_by_name(rSchema, "field1");
int avro_schema_record_field_set_doc_by_index(rSchema, i, value);
int avro_schema_record_field_set_doc_by_name(rSchema, "field1", value);
The reason I ask, and it's problematic, is because such a change would break
existing API functionality. Currently a call to avro_schema_record_field_get
returns the type attribute of an avro_record_field_t. With the proposed change
the new avro_record_field_t would look like:
struct avro_record_field_t {
struct avro_obj_t obj;
int index;
char *name;
avro_schema_t type;
}
Thus, the obj attribute would be returned and a new set of API functions would
be used to access information about a record field:
int avro_schema_field_get_index(fScehma);
char * avro_schema_field_get_name(fSchema);
avro_schema_t avro_schema_field_get_type(fSchema);
avro_value_t avro_schema_field_get_default(fSchema);
char * avro_schema_field_get_doc(fSchema);
Interested in thoughts about the change and possibly why it was designed this
way. Looking at C++ it seems to have the same issue.
Thanks,
- John