Search code examples
scalaavrohortonworks-data-platformconfluent-schema-registry

Avro invalid default for union field


I'm trying to serialise and then write to the hortonworks schema registry an avro schema but I'm getting the following error message during the write operation.

Caused by: java.lang.RuntimeException: An exception was thrown while processing request with message: [Invalid default for field viewingMode: null not a [{"type":"record","name":"aName","namespace":"domain.assembled","fields":[{"name":"aKey","type":"string"}]},{"type":"record","name":"anotherName","namespace":"domain.assembled","fields":[{"name":"anotherKey","type":"string"},{"name":"yetAnotherKey","type":"string"}]}]]
        at com.hortonworks.registries.schemaregistry.client.SchemaRegistryClient.handleSchemaIdVersionResponse(SchemaRegistryClient.java:678)
        at com.hortonworks.registries.schemaregistry.client.SchemaRegistryClient.doAddSchemaVersion(SchemaRegistryClient.java:664)
        at com.hortonworks.registries.schemaregistry.client.SchemaRegistryClient.lambda$addSchemaVersion$1(SchemaRegistryClient.java:591)

This is the avro schema

{
    "type": "record",
    "name": "aSchema",
    "namespace": "domain.assembled",
    "fields": [
        {
            "name": "viewingMode",
            "type": [
                {
                    "name": "aName",
                    "type": "record",
                    "fields": [
                        {"name": "aKey","type": "string"}
                    ]
                },
                {
                    "name": "anotherName",
                    "type": "record",
                    "fields": [
                        {"name": "anotherKey","type": "string"},
                        {"name": "yetAnotherKey","type": "string"}
                    ]
                }
            ]
        }
    ]
}

Whoever if I add a "null" as the first type of the union this the succeeds. Do avro union types require a "null"? In my case this would be an incorrect representation of data so I'm not keen on doing it. If it makes any difference I'm using avro 1.9.1.

Also, apologies if the tags are incorrect but couldn't find a hortonworks-schema-registry tag and don't have enough rep to create a new one.


Solution

  • Turns out if was an issue with hortonwork's schema registry. This has actually already been fixed here and I've requested a new release here. Hopefully this happens soon.