全部, 我很幸运创建了一个包含记录数组的Apache Avro架构,但是当我尝试创建一个记录数组的数组时,python架构解析器失败了。我做错了什么,或者这是一个错误?
{
"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"
}
]
}
]
}
}
]
}
}
]
}
错误消息很长 - 抱歉:
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'
非常感谢任何指导。感谢。
答案 0 :(得分:0)
好吧,老实说,我仍然不太清楚为什么上面的架构失败了,但这个答案就是我想要的:How to define avro schema for complex json document?
这里的答案显示了如何拥有一组记录数组。正是我在特定情况下所需要的。