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
-
Re: help required with json substructure parsing
I am doing this in plain C.

Mahesh
On Fri, Sep 6, 2013 at 10:40 PM, Mahesh V <[EMAIL PROTECTED]>wrote:

> Hello Folks,
>
> First of all, great work. Avro is fantastic.
>
> question.
> 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[] >             "{\
>                 \"type\":\"record\",\
>                 \"name\":\"Person\",\
>                 \"fields\":[\
>                     {\"name\": \"ID\", \"type\": \"long\"},\
>                     {\"name\": \"FirstName\", \"type\": \"string\"},\
>                     {\"name\": \"Email\", \"type\": \"string\"}\
>                     {\
>                         \"type\"   : \"record\",\
>                         \"name\"   : \"ipaddr\",\
>                         \"fields\" : [\
>                             {\"name\": \"Fixed16\", \"type\": \"fixed\",
> \"size\":16},\
>                             {\"name\": \"Fixed4\", \"type\": \"fixed\",
> \"size\":4},\
>                             { \"name\" : \"ip_family\", \"type\" :
> \"long\" },\
>                             { \"name\" : \"hostip\", \"type\" :
> [\"Fixed4\", \"Fixed16\"]},\
>                         ]\
>                     }\
>                 ]\
>              }";
>
> The original add_function is below.
>
>     void
>         add_person(avro_file_writer_t db, const char *name, const char
> *email,
>                 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
> structure\n");
>                 exit(EXIT_FAILURE);
>             }
>             if (avro_file_writer_append(db, person)) {
>                 fprintf(stderr,
>                         "Unable to write Person datum to memory
> buffer\nMessage: %s\n", avro_strerror());
>                 exit(EXIT_FAILURE);
>             }
>             /* Decrement all our references to prevent memory from leaking
> */
>             avro_datum_decref(id_datum);
>             avro_datum_decref(name_datum);
>             avro_datum_decref(email_datum);
>             avro_datum_decref(person);
>         }
> would someone kindly let me know how to modify it so that I can parse
> the ip_addr field as well?
> thanks in advance
>
>
>