Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

How to change csv attribute/header name in apache nifi ?

Solved Go to solution
Highlighted

How to change csv attribute/header name in apache nifi ?

New Contributor

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"

1 ACCEPTED SOLUTION

Accepted Solutions

Re: How to change csv attribute/header name in apache nifi ?

Super Guru

@Vivek Singh

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:-

64982-replacetext.png

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.
1 REPLY 1

Re: How to change csv attribute/header name in apache nifi ?

Super Guru

@Vivek Singh

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:-

64982-replacetext.png

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.