avro:在使用联合记录类型时保留联合记录字段名

lzfw57am  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(225)

我使用kafka流将xml消息转换为avro格式。我想知道,在我的avro模式中使用union type时,是否可以保留union记录的字段名,如下例所示,以便在avro消息中使用“record1”或“record2”,而不是名称“main\u record”,具体取决于我接收的输入数据:

{
    "namespace": "proj.avro",
    "protocol": "app_messages",
    "doc" : "application messages",
    "name": "myRecord",
    "type" : "record",
    "fields": [
    {
    "name": "main_record",
    "type": [
        {
            "name": "record1",
            "type" : "record", 
            "fields": 
            [
                {
                    "name" : "request_id", 
                    "type" : "int"
                },
                {
                    "name" : "message_type",
                    "type" : "int"
                },
                {
                    "name" : "users",
                    "type" : "string"
                }
            ]
        },
        {
            "name" : "record2",
            "type" : "record",
            "fields" :
            [
                {
                    "name" : "request_id",
                    "type" : "int"
                },
                {
                    "name" : "response_code",
                    "type" : "string"
                },
                {
                    "name" : "response_count",
                    "type" : "int"
                },
                {
                    "name" : "reason_code",
                    "type" : "string"
                }
            ]
        }
    ]
    }
    ]
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题