avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Saptarshi Guha <sg...@mozilla.com>
Subject Re: Adding array elements to record in a union
Date Wed, 11 Jul 2012 08:18:35 GMT
As a follow up, avro_json of field_c displays the content 'v' e.g.

{
  "int": {
    "v": [
      2,
      1,
      5
    ]
  }
}


but i'd rather get (rvalue)
{
"c":
 {
  "int": {
    "v": [
      2,
      1,
      5
    ]
  }
 }
}

----- Original Message -----
> From: "Saptarshi Guha" <sguha@mozilla.com>
> To: "avro" <user@avro.apache.org>
> Sent: Wednesday, July 11, 2012 12:53:41 AM
> Subject: Adding array elements to record in a union
> 
> Hello,
> 
> Below is the avro file. I'm trying to write an object of the form
> {
>   "c": {"name":"int",....}
> }
> 
> Here's how i go about it
> 
>   // aschema contains the schema for [1]
>   avro_value_iface_t  *robject_iface =
>   avro_generic_class_from_schema(*aschema);
>   avro_value_t rvalue,field_c,branch,branch_v;
>   // New container, and go to element "c" (ie. index==1)
>   avro_generic_value_new(robject_iface, &rvalue);
>   avro_value_get_by_index(&rvalue, 1, &field_c, NULL);
>   // No go into discriminant == 1 (integers)
>   avro_value_set_branch(&field_c,1,&branch);
>   // This is a record, so access it's 'v' field
>   avro_value_get_by_index(&branch,0,&branch_v,NULL);
>   for(int i=0;i < LENGTH; i++){
>   	avro_value_t  element;
> 	size_t  new_index;
> 	avro_value_append(&branch_v, &element, &new_index);
> 	avro_value_set_int(&element,robj[i]);
>   }
> 
> As expected, branch_v when displayed as JSON shows [1,2,3 ...]
> (contents of robj)
> But the JSON of rvalue is empty ... (and it's size
> 'avro_value_sizeof' is 0).
> 
> What am i doing wrong?
> 
> Regards
> Saptarshi
> Avro 1.7
> 
> [1]
> {
>     "namespace": "robjects.avro",
>     "type": "record",
>     "name": "robject",
>     "fields": [
> 	{"name":"a" ,"type":["null",{"type":"map"
> 	 ,"values":"robject"}],"comments":"Attributes"},
> 	{"name":"c","type":[
> 	    "null",
> 	    {"name":"int", "type":"record"
> 	    ,"fields":[{"name":"v","type":{"type":"array"
> 	    ,"items":"int"}}]},
> 	    {"name":"real","type":"record"
> 	    ,"fields":[{"name":"v","type":{"type":"array"
> 	    ,"items":"double"}}]},
> 	    {"name":"list","type":"record"
> 	    ,"fields":[{"name":"v","type":{"type":"array"
> 	    ,"items":"robject"}}]}
> 	    ]
> 	 ,"comments": "Content"}
>     ]
> }
> 
> 
> 

Mime
View raw message