- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
How to change csv attribute/header name in apache nifi ?
- Labels:
-
Apache NiFi
Created ‎04-02-2018 06:08 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am using apache nifi to convert json to csv. I want to change the headers of the generated csv . Is there any specific processor for this. I know how to achieve this using ExecuteScript processor but is there any easy approach.
Ex.
"_id", "name","time" to "id", "browser_name","duration"
Created on ‎04-02-2018 06:23 AM - edited ‎08-17-2019 09:33 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
we can add user defined header by using replace text processor instead of writing any script.
For this case in your csvsetwriter controller service change the below property to false,
Include Header Line
false
now we are not going to get the header line included in the output flowfile, then use Replace text processor to add our own header to the flowfile content.
Replace text configs:-
Search Value
(?s)(^.*$)
Replacement Value
"_id", "name","time" to "id", "browser_name","duration"
Character Set
UTF-8
Maximum Buffer Size
1 MB //needs to change the value according to the file size that we are getting after convertrecord processor
Replacement Strategy
Prepend //we are prepend the the content with the above header line
Evaluation Mode
Entire text
Input content:-
sample content from convert record processor is as follows
"1","foo","12:00AM" to "123","Mozilla","1hr"
Output Content:-
we are adding our header to the above flowfile content the output flowfile content from replacetext processor would be
"_id", "name","time" to "id", "browser_name","duration" "1","foo","12:00AM" to "123","Mozilla","1hr"
If the Answer helped to resolve your issue, Click on Accept button below to accept the answer, That would be great help to Community users to find solution quickly for these kind of issues.
Created on ‎04-02-2018 06:23 AM - edited ‎08-17-2019 09:33 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
we can add user defined header by using replace text processor instead of writing any script.
For this case in your csvsetwriter controller service change the below property to false,
Include Header Line
false
now we are not going to get the header line included in the output flowfile, then use Replace text processor to add our own header to the flowfile content.
Replace text configs:-
Search Value
(?s)(^.*$)
Replacement Value
"_id", "name","time" to "id", "browser_name","duration"
Character Set
UTF-8
Maximum Buffer Size
1 MB //needs to change the value according to the file size that we are getting after convertrecord processor
Replacement Strategy
Prepend //we are prepend the the content with the above header line
Evaluation Mode
Entire text
Input content:-
sample content from convert record processor is as follows
"1","foo","12:00AM" to "123","Mozilla","1hr"
Output Content:-
we are adding our header to the above flowfile content the output flowfile content from replacetext processor would be
"_id", "name","time" to "id", "browser_name","duration" "1","foo","12:00AM" to "123","Mozilla","1hr"
If the Answer helped to resolve your issue, Click on Accept button below to accept the answer, That would be great help to Community users to find solution quickly for these kind of issues.
Created ‎02-05-2020 01:55 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Instead of using the function: prepend (this just shifts your data), how do you do an outright replace for the header row? I tried using Literal search, but I end up having strange characters when the replace occurs
