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

Switch to Threaded View
Avro >> mail # user >> help required with json substructure parsing

Copy link to this message
help required with json substructure parsing
Hello Folks,

First of all, great work. Avro is fantastic.

I have a json as shown below.
I would like to parse person fields including ip_addr so that
it can be packed.

   const char  PERSON_SCHEMA[]             "{\
                    {\"name\": \"ID\", \"type\": \"long\"},\
                    {\"name\": \"FirstName\", \"type\": \"string\"},\
                    {\"name\": \"Email\", \"type\": \"string\"}\
                        \"type\"   : \"record\",\
                        \"name\"   : \"ipaddr\",\
                        \"fields\" : [\
                            {\"name\": \"Fixed16\", \"type\": \"fixed\",
                            {\"name\": \"Fixed4\", \"type\": \"fixed\",
                            { \"name\" : \"ip_family\", \"type\" : \"long\"
                            { \"name\" : \"hostip\", \"type\" :
[\"Fixed4\", \"Fixed16\"]},\

The original add_function is below.

        add_person(avro_file_writer_t db, const char *name, const char
                const char *phone, char* ip, long iptype)
            avro_datum_t person = avro_record(person_schema);
            avro_datum_t id_datum = avro_int64(++id);
            avro_datum_t name_datum = avro_string(name);
            avro_datum_t email_datum = avro_string(email);
            if (avro_record_set(person, "ID", id_datum)
                    || avro_record_set(person, "FirstName", name_datum)
                    || avro_record_set(person, "Email", email_datum)) {
                fprintf(stderr, "Unable to create Person datum
            if (avro_file_writer_append(db, person)) {
                        "Unable to write Person datum to memory
buffer\nMessage: %s\n", avro_strerror());
            /* Decrement all our references to prevent memory from leaking
would someone kindly let me know how to modify it so that I can parse
the ip_addr field as well?
thanks in advance