Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

ReplaceText: write content on empty flowfile does nothing but sends to success queue

avatar
New Contributor

Hello. Well, I have a nifi flow that is triggered by a ListFile processor. ListFile creates an empty content flowfile and sends it to success queue.
I want to write some fixed content ( say "id,description,date" ) on this empty flowfile. The goal is to write an empty csv with that header in HDFS  as first action of the flow.
So I was trying to use ReplaceText for writing the content to the empty flowfile.
The flow looks like this    ListFile ---> ReplaceText (see image below)

image1.png

ReplaceText has the following settings: Replacement Strategy = Always Replace, Replacement Value = id,description,date


At first I thougt that ReplaceText could fail cause incoming flowfile had no content.
But ReplaceText sent the flowfile to success BUT NO CONTENT WAS WRITTEN (It is still empty)
In the image below you can see that Queued Bytes are 0

image2.png

 

 

Setting Bulletin Level to "DEBUG" just throws the following message : "ReplaceText[id=501319d3-354d-1482-6c84-d176639be85f] Transferred FlowFile[filename=Control de trabajos de pala - Control punto a punto.csv] to 'success'"

 

Is Replacetext supposed to write content on an empty file ?
If not then empty flowfile should be sent to failure queue, right ?

 

Note: for reproducing the bug (I guess we can call it a bug), you can use GenerateFlowfile instead of ListFile and you will get the same result.


Thanks for any feed back. I guess i will have to use a ExecuteScript processor which is a bit more dificult.
 

1 ACCEPTED SOLUTION

avatar

Hi,

I dont think there is a bug here. It all depends on the value you set in ReplaceText for the Evaluation Mode property. My guess is that you have set to the default value which is "Line-by-Line" which makes sense in this case because you have no lines. To make this work you need to set it to "Entire Text" instead as follows:

 

SAMSAL_0-1683222229230.png

 

If you want to check if the file  coming from the ListFile to see if it has content or not and then  route accordingly , you can use RouteOnAttribute to check against the built-in flow file attribute "fileSize" using expression language: ${fileSize:equals(0)}

 

If that helps please accept solution.

Thanks

 

 

View solution in original post

3 REPLIES 3

avatar
Community Manager

@martinpla Welcome to the Cloudera Community!

To help you get the best possible solution, I have tagged our NiFi experts @MattWho and @cotopaul  who may be able to assist you further

Please keep us updated on your post, and we hope you find a satisfactory solution to your query.


Regards,

Diana Torres,
Community Moderator


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:

avatar

Hi,

I dont think there is a bug here. It all depends on the value you set in ReplaceText for the Evaluation Mode property. My guess is that you have set to the default value which is "Line-by-Line" which makes sense in this case because you have no lines. To make this work you need to set it to "Entire Text" instead as follows:

 

SAMSAL_0-1683222229230.png

 

If you want to check if the file  coming from the ListFile to see if it has content or not and then  route accordingly , you can use RouteOnAttribute to check against the built-in flow file attribute "fileSize" using expression language: ${fileSize:equals(0)}

 

If that helps please accept solution.

Thanks

 

 

avatar
New Contributor

Hi @SAMSAL , thanks for your response. You are right, changing to "Entire Text" worked
I was in a hurry and didnt try changing the evaluation mode. I supposed that "Always Replace" would do the work.
Thank you