Created 03-04-2023 06:55 PM
How can I use Apache NiFi to transform the current output of my Oracle database to the desired output format, as shown below? Desier out should be as mention below Avro format
Current output:
{ "type":"record", "name":"nifiRecord", "namespace":"org.apache.nifi", "fields":[ {"name":"AGENT_CODE", "type":["null","string"]}, {"name":"CORR_ACC_NO", "type":["null","string"]}, {"name":"LOCAL_ACC_NO", "type":["null","string"]} ] }
Desired output:
{ "type": "record", "name": "Bank", "namespace": "com.xyz.model.vo", "fields":[ {"name": "instance", "type": "string"}, {"name": "agent_code", "type": "string"}, {"name": "corr_acc_no", "type": "long"}, {"name": "local_acc_no", "type": "string"} ] }
What steps do I need to take in NiFi to achieve this transformation and output the results to the desired format? especially for changing { "type": "record", "name": "Bank", "namespace": "com.xyz.model.vo"
Created 03-05-2023 06:39 AM
Hi,
You have few options like UpdateRecord Processor or JoltJsonTrnasformation. I recommend the UpdateRecord , for more information on how to use please refer to :
It should be straight forward if you use the "Replace with Literal" strategy.
If that helps please accept solution
Thanks
"
Created 03-05-2023 02:05 PM
Still, I am not able to replace
{ "type":"record", "name":"nifiRecord", "namespace":"org.apache.nifi",
to
{ "type": "record", "name": "Bank", "namespace": "com.xyz.model.vo", "fields":
Created 03-05-2023 04:40 PM
I apologize, I forgot that you are talking about an Avro format and not json. In this I think you need to pass your own avro schema. You can first convert Avro to Json using ConvertAvroToJSON processor , then use ConvertRecrod which can be configured as follows:
In the AvroRecordWrite , you can set your schema with the proper record\namespace values. For Example in my case I used the "User Schema Text" strategy and either provide the schema directly in the Schema Text Property or reference it using flowfile attribute ${avro.schema} using Expression Language.
The Schema Text :
{
"type": "record",
"name": "bank",
"namespace": "org.xyz.com",
"fields": [
{
"name": "AGENT_CODE",
"type": [
"null",
"string"
]
},
{
"name": "CORR_ACC_NO",
"type": [
"null",
"string"
]
},
{
"name": "LOCAL_ACC_NO",
"type": [
"null",
"string"
]
}
]
}
Hope that helps