gpt4 book ai didi

java - 如何为嵌套集合创建 avro 模式?

转载 作者:行者123 更新时间:2023-11-30 06:15:43 26 4
gpt4 key购买 nike

我确实有这样的身材 -

{
{
"name":"abc",
"eventName": "abc",
"pl": {
"name": "xyz",
"age": 21,
"address": {
"line1" : "h.no - ",
"line2": "state"
}
}
}
}

任何人都可以帮我为这种主体创建一个有效的 Avro 架构吗?我找到了一个创建像这样的嵌套模式的示例 -

[
{
"type": "record",
"name": "Address",
"fields": [
{
"name": "streetaddress",
"type": "string"
},
{
"name": "city",
"type": "string"
}
]
},


{
"type": "record",
"name": "person",
"fields": [
{
"name": "firstname",
"type": "string"
},
{
"name": "lastname",
"type": "string"
},
{
"name": "address",
"type": "Address"
}
]

}]

当我提供这种模式时,它在下面的行中提供了错误 -

GenericRecord avroRecord = new GenericData.Record(schema);

错误是 - org.apache.avro.AvroRuntimeException:不是记录架构:

最佳答案

您可以像这样定义记录以支持嵌套对象。

{

"type": "record",
"name": "person",
"fields": [{
"name": "firstname",
"type": "string"
}, {
"name": "lastname",
"type": "string"
}, {
"name": "address",
"type": {
"type": "record",
"name": "Address",
"fields": [{
"name": "streetaddress",
"type": "string"
}, {
"name": "city",
"type": "string"
}
]
}
}
]
}

关于java - 如何为嵌套集合创建 avro 模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49251403/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com