All, I've had luck creating an Apache Avro schema with an array of records, but when I then try to make an array of an array of records, the python schema parser fails. Am I doing something wrong, or is this a bug?
{
"type": "record",
"name": "userInfo",
"namespace": "my.example",
"fields": [
{
"name": "ID",
"type": "string",
"default": "NONE"
},
{
"name": "message_timestamp",
"type": "long"
},
{
"name": "location",
"type": [
"null",
"string"
],
"default": "NONE"
},
{
"name": "AttributeMapping0",
"type": {
"type": "array",
"items": [
{
"name": "timestamp",
"type": "long"
},
{
"name": "AttributeMapping1",
"type": {
"type": "array",
"items": [
{
"name": "AttributeMapping2",
"type": "record",
"fields": [
{
"name": "Name",
"type": "string"
},
{
"name": "Value",
"type": "long"
}
]
}
]
}
}
]
}
}
]
}
The error message is very long - sorry:
File "/usr/local/lib/python3.4/dist-packages/avro_python3-1.8.0-py3.4.egg/avro/schema.py", line 1283, in Parse
return SchemaFromJSONData(json_data, names)
File "/usr/local/lib/python3.4/dist-packages/avro_python3-1.8.0-py3.4.egg/avro/schema.py", line 1254, in SchemaFromJSONData
return parser(json_data, names=names)
File "/usr/local/lib/python3.4/dist-packages/avro_python3-1.8.0-py3.4.egg/avro/schema.py", line 1182, in _SchemaFromJSONObject
other_props=other_props,
File "/usr/local/lib/python3.4/dist-packages/avro_python3-1.8.0-py3.4.egg/avro/schema.py", line 1061, in __init__
fields = make_fields(names=nested_names)
File "/usr/local/lib/python3.4/dist-packages/avro_python3-1.8.0-py3.4.egg/avro/schema.py", line 1173, in MakeFields
return tuple(RecordSchema._MakeFieldList(field_desc_list, names))
File "/usr/local/lib/python3.4/dist-packages/avro_python3-1.8.0-py3.4.egg/avro/schema.py", line 986, in _MakeFieldList
yield RecordSchema._MakeField(index, field_desc, names)
File "/usr/local/lib/python3.4/dist-packages/avro_python3-1.8.0-py3.4.egg/avro/schema.py", line 957, in _MakeField
names=names,
File "/usr/local/lib/python3.4/dist-packages/avro_python3-1.8.0-py3.4.egg/avro/schema.py", line 1254, in SchemaFromJSONData
return parser(json_data, names=names)
File "/usr/local/lib/python3.4/dist-packages/avro_python3-1.8.0-py3.4.egg/avro/schema.py", line 1197, in _SchemaFromJSONObject
items=SchemaFromJSONData(items_desc, names),
File "/usr/local/lib/python3.4/dist-packages/avro_python3-1.8.0-py3.4.egg/avro/schema.py", line 1254, in SchemaFromJSONData
return parser(json_data, names=names)
File "/usr/local/lib/python3.4/dist-packages/avro_python3-1.8.0-py3.4.egg/avro/schema.py", line 1142, in _SchemaFromJSONArray
return UnionSchema(map(MakeSchema, json_array))
File "/usr/local/lib/python3.4/dist-packages/avro_python3-1.8.0-py3.4.egg/avro/schema.py", line 866, in __init__
self._schemas = tuple(schemas)
File "/usr/local/lib/python3.4/dist-packages/avro_python3-1.8.0-py3.4.egg/avro/schema.py", line 1141, in MakeSchema
return SchemaFromJSONData(json_data=desc, names=names)
File "/usr/local/lib/python3.4/dist-packages/avro_python3-1.8.0-py3.4.egg/avro/schema.py", line 1254, in SchemaFromJSONData
return parser(json_data, names=names)
File "/usr/local/lib/python3.4/dist-packages/avro_python3-1.8.0-py3.4.egg/avro/schema.py", line 1154, in _SchemaFromJSONObject
if type in PRIMITIVE_TYPES:
TypeError: unhashable type: 'dict'
Any guidance would be much appreciated. Thanks.
Okay, so honestly I'm still not particularly sure on why the schema above fails, but this answer was what I was looking for: How to define avro schema for complex json document?
This answer here shows how to have an array of arrays of records. Just what I needed in my particular case.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.