How to create schema containing list of objects using Avro?
有人知道如何创建包含某个类的对象列表的Avro模式吗?
我希望生成的类如下所示:
1 2 3 4 5 6 7 |
为此,我已经编写了模式文件的一部分,但不知道如何告诉Avro创建
我的架构文件如下所示:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | { "name":"Parent", "type":"record", "fields":[ { "name":"children", "type":{ "name":"Child", "type":"record", "fields":[ {"name":"name","type":"string"} ] } } ] } |
现在的问题是我可以将字段
任何人都可以帮忙吗?
您需要使用数组类型来创建列表。
以下是处理您的用例的更新架构。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | { "name":"Parent", "type":"record", "fields":[ { "name":"children", "type":{ "type":"array", "items":{ "name":"Child", "type":"record", "fields":[ {"name":"name","type":"string"} ] } } } ] } |
我有以下课程,avro maven插件相应地生成了两个课程:
1 2 3 4 5 6 7 8 9 10 |
Avro文件格式:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | { "type":"record", "namespace":"com.mypackage", "name":"AccountEvent", "fields": [ { "name":"accountNumber", "type":"string" }, { "name":"address", "type":"string" }, { "name":"accountList", "type": { "type":"array", "items":{ "name":"Account", "type":"record", "fields":[ { "name":"accountNumber", "type":"string" }, { "name":"id", "type":"string" } ] } } } ] } |