Avro Schema Error - Unknown union branch

Hi Team,

  i have setup Confluent Platform 6.1.0 locally using Docker Images. I have setup topic in Control Center and added AVRO Schema for the topic. Below is the Schema.

{
“fields”: [
{
“name”: “partyIdentifier”,
“type”: “string”
},
{
“doc”: “Party First name.”,
“name”: “partyName1”,
“type”: “string”
},
{
“doc”: “Party Middle Name.”,
“name”: “partyName2”,
“type”: “string”
},
{
“doc”: “Party Last Name.”,
“name”: “partyName3”,
“type”: “string”
},
{
“name”: “PartyAddress”,
“type”: [
“null”,
{
“fields”: [
{
“name”: “Address1”,
“type”: “string”
},
{
“name”: “Address2”,
“type”: “string”
}
],
“name”: “PartyAddress”,
“type”: “record”
}
]
}
],
“name”: “Party”,
“namespace”: “Confluent.Kafka.Model.ClientSpecific”,
“type”: “record”
}

When i am trying to publish message to the topic getting following error

{
“error_code”: 42203,
“message”: “Conversion of JSON to Object failed: Failed to convert JSON to Avro: Unknown union branch Address1”
}

Am using Rest Proxy to publish message. Below is the message i am passing

{
“records”: [
{
“value”: {
“partyIdentifier”: “1312323”,
“partyName1”: “Nishanth”,
“partyName2”: “”,
“partyName3”: “P”,
“PartyAddress”: {
“Address1”: {
“string”: “Test”
},
“Address2”: {
“string”: “Test”
}
}
}
}
],
“value_schema”: “{\n "doc": "Sample schema to help you get started.",\n "fields": [\n {\n "doc": "The string type is a unicode character sequence.",\n "name": "partyIdentifier",\n "type": "string"\n },\n {\n "doc": "Party First name.",\n "name": "partyName1",\n "type": "string"\n },\n {\n "doc": "Party Middle Name.",\n "name": "partyName2",\n "type": "string"\n },\n {\n "doc": "Party Last Name.",\n "name": "partyName3",\n "type": "string"\n },\n {\n "name": "PartyAddress",\n "type": [\n "null",\n {\n "name": "PartyAddress",\n "namespace": "Confluent.Kafka.Model.ClientSpecific",\n "type": "record",\n "fields": [\n {\n "name": "Address1",\n "type": "string"\n },\n {\n "name": "Address2",\n "type": "string"\n }\n ]\n }\n ]\n }\n ],\n "name": "Party",\n "namespace": "Confluent.Kafka.Model.ClientSpecific",\n "type": "record"\n}”
}

If i pass null to PartyAddress, its working. if i pass record type getting Unknown union branch error. Please help me to resolve the issue.

Thanks,
Nishanth P

We are having the same issue - were you ever able to resolve this and if so, how?

@chris.vaughn

    Yes, i have fixed. The work around for the issue is the Avro Schema should be defined as below

Avro Schema:

{
“fields”: [
{
“name”: “partyIdentifier”,
“type”: “string”
},
{
“doc”: “Party First name.”,
“name”: “partyName1”,
“type”: “string”
},
{
“doc”: “Party Middle Name.”,
“name”: “partyName2”,
“type”: “string”
},
{
“doc”: “Party Last Name.”,
“name”: “partyName3”,
“type”: “string”
},
{
“name”: “PartyAddress”,
“type”: [
“null”,
{
“fields”: [
{
“name”: “Address1”,
“type”: “string”
},
{
“name”: “Address2”,
“type”: “string”
}
],
“name”: “PartyAddress”,
“type”: “record”,
“namespace”:“Confluent.Kafka.Model.ClientSpecific”
}
]
}
],
“name”: “Party”,
“namespace”: “Confluent.Kafka.Model.ClientSpecific”,
“type”: “record”
}

Json Data:

{
“records”: [
{
“value”: {
“partyIdentifier”: “1312323”,
“partyName1”: “Nishanth”,
“partyName2”: “”,
“partyName3”: “P”,
“PartyAddress”: {
“Confluent.Kafka.Model.ClientSpecific.PartyAddress”: {
“Address1”: “Test”,
“Address2”: “Test”
}
}
}
}
]
}

In case if Address 1 and Address 2 also declared as Union Type, then the Json should look as below

{
“records”: [
{
“value”: {
“partyIdentifier”: “1312323”,
“partyName1”: “Nishanth”,
“partyName2”: “”,
“partyName3”: “P”,
“PartyAddress”: {
“Confluent.Kafka.Model.ClientSpecific.PartyAddress”: {
“Address1”: {
“string”: “Test”
},
“Address2”: {
“string”: “Test”
}
}
}
}
}
]
}

Thank you for the fast reply. So to summarize, you only added the ““namespace”: “Confluent.Kafka.Model.ClientSpecific”,” namespace to all record types in the Schema. Is that correct?

Yes, and also if you noticed in JSON payload for PartyAddress you can see the difference. Below is the difference

PartyAddress Decalred as Union Type:
“PartyAddress”: {
“Confluent.Kafka.Model.ClientSpecific.PartyAddress”: {
“Address1”: “Test”,
“Address2”: “Test”
}
}

PartyAddress Decalred as Non-Union Type:
“PartyAddress”: {
“Address1”: “Test”,
“Address2”: “Test”
}