[英]Apache Avro: Complex POJO Objects as values of a Map
Consider some POJOs such as follows.考虑一些 POJO,如下所示。
class Configuration {
private String id;
private Map<String, LocationConfig> locationConfiguration;
}
class LocationConfig {
private String locationId;
private Integer capacity;
private Boolean available;
}
How can I come up with a JSON based Avro schema for the above?我如何为上述内容提出基于 JSON 的 Avro 模式? As far as I could find, even though maps are supported in Avro, the key type should always be String (which I can somehow live with) and the values cannot be of
Record
type.据我所知,即使 Avro 支持映射,键类型也应始终为 String(我可以以某种方式接受)并且值不能为
Record
类型。 Is there a way around this?有没有解决的办法? The documentation has only follows.
文档只有以下内容。
Upon research I could find somewhat of a similar question , which doesn't look very useful.经过研究,我可以找到一些类似的问题,但看起来不是很有用。
Yes you can add complex POJO as Map's value.是的,您可以添加复杂的 POJO 作为 Map 的值。
For eg I had below schema initially例如,我最初有以下架构
{
"type": "record",
"name": "click_event",
"namespace": "exercise2",
"fields": [
{"name": "email", "type": "string"},
{"name": "timestamp", "type": "string"},
{"name": "uri", "type": "string"},
{"name": "number", "type": "int"},
],
}
Then I wanted to add a complex type ie map which in turn contained POJO objects.然后我想添加一个复杂类型,即 map,它又包含 POJO 对象。
{
'about':
ClickAttribute(element='a', content='reinvent intuitive infrastructures'),
'index':
ClickAttribute(element='button', content='repurpose cross-media schemas')
}
I added it in this way我是这样添加的
{
"type": "record",
"name": "click_event",
"namespace": "exercise2",
"fields": [
{"name": "email", "type": "string"},
{"name": "timestamp", "type": "string"},
{"name": "uri", "type": "string"},
{"name": "number", "type": "int"},
# Below complex type is added by me.
{
"name" : "attributes",
"type" : {
"type" : "map",
"values" : {
"name" : "click_attribute",
"type" : "record",
"fields" : [
{"name" : "element", "type" : "string"},
{"name" : "content", "type" : "string"}
]
}
}
}
],
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.