Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avro ENUM field

Tags:

null

avro

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).

like image 772
user9750148 Avatar asked May 11 '18 01:05

user9750148


1 Answers

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"]
                }
            ]
        }
    ]
}
like image 89
hlagos Avatar answered Nov 15 '22 15:11

hlagos