Avro ENUM field

隐身守侯 提交于 2019-12-11 06:29:07

问题


I am trying to create Union field in Avro schema and send corresponding JSON message with it but to have one of the fields - null.

https://avro.apache.org/docs/1.8.2/spec.html#Unions

What is example of simplest UNION type (avro schema) with corresponding JSON data? (trying to make example without null/empty data and one with null/empty data).


回答1:


Here you have an example.

Null enum

{"name": "Stephanie", "age": 30, "sex": "female", "myenum": null}

Not null enum

{"name": "Stephanie", "age": 30, "sex": "female", "myenum": "HEARTS"}

Schema

{
    "type": "record",
    "name": "Test",
    "namespace": "com.acme",
    "fields": [{
            "name": "name",
            "type": "string"
        }, {
            "name": "age",
            "type": "int"
        }, {
            "name": "sex",
            "type": "string"
        }, {
            "name": "myenum",
            "type": ["null", {
                    "type": "enum",
                    "name": "Suit",
                    "symbols": ["SPADES", "HEARTS", "DIAMONDS", "CLUBS"]
                }
            ]
        }
    ]
}


来源:https://stackoverflow.com/questions/50283736/avro-enum-field

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!