Support Questions

Find answers, ask questions, and share your expertise

Avro Schema field to accept string and dynamic array

avatar
New Contributor

Dear Team,

I am trying to create an AVRO schema where a field can accept both string data(Expected Format 2) and a dynamic array (Expected Format 1).

AVRO schema has event/processFlow/characteristic []/value which is supposed to accept both dynamic array and string. For the “object_avro”, we are passing “object_json” as input. However as per "object_avro it is accepting only Expected Format 1 JSON block.

Kindly provide us a solution where an AVRO schema can accept both Expected Format 1 and Expected Format 2 JSON's.

Avro Schema:

{
"doc": "Sample schema to help you get started",
"fields": [
{
"name": "event",
"type": {
"fields": [
{
"name": "processFlow",
"type": {
"fields": [
{
"name": "id",
"type": "string"
},
{
"name": "characteristic",
"type": {
"items": {
"fields": [
{
"default": null,
"name": "id",
"type": [
"null",
"string"
]
},
{
"default": null,
"name": "name",
"type": [
"null",
"string"
]
},
{
"default": null,
"name": "valueType",
"type": [
"null",
"string"
]
},
{
"name": "value",
"type": {
"items": {
"type": "map",
"values": [
"string",
"null",
"int",
"boolean"
]
},
"type": "array"
}
},
{
"default": null,
"name": "baseType",
"type": [
"null",
"string"
]
},
{
"default": null,
"name": "schemaLocation",
"type": [
"null",
"string"
]
},
{
"default": null,
"name": "type",
"type": [
"null",
"string"
]
}
],
"name": "characteristic",
"type": "record"
},
"type": "array"
}
}




],
"name": "processFlow",
"type": "record"
}
}
],
"name": "event",
"type": "record"
}
}
],
"name": "processFlowManagement",
"namespace": "value.stc.b2b.processFlowManagement",
"type": "record"
}

Expected Format 1

"value":[
{
"name":{"string":"abcd"},
"partnerId":{"int":123},
"partnerType":{"boolean":true}
},
{
"custom":{"string":"abcd"},
"id":{"int":123},
"partnerType":{"boolean":true}
}
]

Expected Format 2

"value":{"string":"hello"}

has context menu

1 REPLY 1

avatar
Community Manager

@albelide, Welcome to our community! To help you get the best possible answer, I have tagged our Kafka experts @Babasaheb @Yuexin Zhang who may be able to assist you further.

Please feel free to provide any additional information or details about your query, and we hope that you will find a satisfactory solution to your question.



Regards,

Vidya Sargur,
Community Manager


Was your question answered? Make sure to mark the answer as the accepted solution.
If you find a reply useful, say thanks by clicking on the thumbs up button.
Learn more about the Cloudera Community: