Created 05-04-2023 09:57 AM
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)
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
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.
Created 05-04-2023 10:48 AM
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:
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
Created 05-04-2023 09:59 AM
@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,Created 05-04-2023 10:48 AM
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:
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
Created on 05-04-2023 10:55 AM - edited 05-04-2023 10:56 AM
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