如何使用Avro创建包含对象列表的架构? [英] How to create schema containing list of objects using Avro?

查看:89
本文介绍了如何使用Avro创建包含对象列表的架构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何创建包含某个类的对象列表的Avro模式吗?

Does anyone knows how to create Avro schema which contains list of objects of some class?

我希望生成的类如下所示:

I want my generated classes to look like below :

class Child {
    String name;
}

class Parent {
    list<Child> children;
}

为此,我已经编写了架构文件的一部分,但不知道如何告诉Avro创建 Children 类型的对象列表?

For this, I have written part of schema file but do not know how to tell Avro to create list of objects of type Children?

我的架构文件如下所示:

My schema file looks like below :

{
    "name": "Parent",
    "type":"record",
    "fields":[
        {
            "name":"children",
            "type":{
                "name":"Child",
                "type":"record",
                "fields":[
                    {"name":"name", "type":"string"}
                ]
            }
        }
    ] 
}

现在的问题是,我可以将字段 children 标记为 Child 类型或数组,但不知道如何将其标记为类型为object的 array孩子班?

Now problem is that I can mark field children as either Child type or array but do not know how to mark it as a array of objects of type Child class?

任何人都可以帮忙吗?

推荐答案

您需要使用

You need to use array type for creating the list. Following is the updated schema that handles your usecase.

{
    "name": "Parent",
    "type":"record",
    "fields":[
        {
            "name":"children",
            "type":{
                "type": "array",  
                "items":{
                    "name":"Child",
                    "type":"record",
                    "fields":[
                        {"name":"name", "type":"string"}
                    ]
                }
            }
        }
    ] 
}

这篇关于如何使用Avro创建包含对象列表的架构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆