0

I am trying to use avro in python to serialize XML data. I can figure out the optional field coding, but how do I do repeated fields?

For example, given this schema, how do I make favorite_number a repeated field so that someone can have more than one favorite_number?

{"namespace": "example.avro",
 "type": "record",
 "name": "User",
 "fields": [
     {"name": "name", "type": "string"},
     {"name": "favorite_number",  "type": "int"},
     {"name": "favorite_color", "type": ["string", "null"]}
 ]
}
anonygrits
  • 1,459
  • 2
  • 14
  • 19

1 Answers1

0

From the specification, maybe something like this...

# For example, a linked-list of 64-bit values may be defined with:

{
   "type": "record", 
   "name": "LongList",
   "aliases": ["LinkedLongs"],                      // old name for this
   "fields" : [
       {"name": "value", "type": "long"},             // each element has a long
       {"name": "next", "type": ["LongList", "null"]} // optional next element
   ]
}

Or you could use an array...

# Arrays use the type name "array" and support a single attribute:
#
# items: the schema of the array's items.
# For example, an array of strings is declared with:

{"type": "array", "items": "int"}

Additionally, you can nest records like so.

Community
  • 1
  • 1
vincent
  • 1,370
  • 2
  • 13
  • 29
  • It looks like an array is right, but there are several kinds. I found this & am working through the thread right now... http://apache-avro.679487.n3.nabble.com/Schema-for-array-of-records-td2710382.html Here is what I ended up with: {"namespace": "example.avro", "type": "record", "name": "User", "fields": [ {"name": "name", "type": "string"}, {"name": "favorite_number", "type": {"type": "array", "items": "int"}}, {"name": "favorite_color", "type": ["string", "null"]} ] } – anonygrits Apr 16 '15 at 18:43