Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Support Questions

Find answers, ask questions, and share your expertise
Announcements
Share your experience with Cloudera on G2 and get a $25 Amazon Gift card.
Hi, I'm CLEO! Something exciting is coming to the Community. Stay Tuned!

Avro Schema field to accept string and dynamic array

avatar
New Member

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: