Created on 09-07-2017 06:26 PM - edited 09-16-2022 05:12 AM
I am new to Nifi and exploring Nifi to generate CSV file from a database table and as part of this exercise using 'QueryDatabaseTable' processor to extract data and then converting to JSON flowfile-attribute with the following sequence of processors: QueryDatabaseTable--> ConvertAvrotoJSON-->EvaluateJSONPath-->AttributestoJSON-->ReplaceText-->PutFile
And below is the sample records output claim from the data provenance of 'AttributesToJSON' processor
{"Code": "ABC", "Desc": "ABC DESC"}
{"Code": "DEF", "Desc": "DEF DESC"}
{"Code": "XYZ", "Desc": "XYZ DESC"}
Target CSV file has to be as follows along with header
Code, Desc (Header)
ABC,ABC DESC
DEF,DEF DESC
XYZ,XYZ DESC
Can you help me to configure required properties for "ReplaceText" processor like Search Value, Replacement Value
Any processor/inputs/examples on how to generate CSV file output directly from Database table?
Created 09-07-2017 06:27 PM
There are some URLs at the end for other articles about the Record Readers/Writers. In your scenario, you would use the AvroReader and the CSVRecordSetWriter in your ConvertRecord processor
Created on 09-08-2017 07:09 AM - edited 08-18-2019 02:06 AM
hi @G Sankar
To make the current flow working, you can remove the AttributetoJSON processor
now the flow would be
QueryDatabaseTable--> ConvertAvrotoJSON-->EvaluateJSONPath-->ReplaceText-->PutFile
EvaluteJSONPath will make sure that the results of those expressions are assigned to FlowFile Attributes, now we can replace the entire flow file content with attributes.
the parameters of the Replace text would be
Search Value : (^.*$)
replace values : ${col1},${col2},${col3}.. etc
col1,2,3 will be attributes of the flow file which extracted by evaluteJSONPath(you may see the flow file attributes in provenence ).
on the other note latest version of the NiFi offer the Convert Record processor where you can convert straight from Avro to CSV using controller service.
Created 09-08-2017 08:33 AM
Thanks Everyone, I will try and get back to you if any questions
,Thanks Raju & Lim, l will try and let you know both if any questions
Created 09-11-2017 02:40 PM
Hi, I tried to implement using ConvertRecord Processor and getting below error:
SchemaNotFoundException: Flow File did not contain appropriate attributes to determine Schema Name.