- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Delete/Stop flow files in execute script
- Labels:
-
Apache NiFi
Created on ‎03-16-2018 12:17 PM - edited ‎08-18-2019 12:54 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Team,
I want to either delete or stop the flow files which didn't satisfy the condition in execute script.
I'm getting lot of flow files into my execute script processor out of which didn't satisfy the condition needs to be stopped/deleted at the execute script processor it self and whichever the flow files satisfy the condition needs to move to the next step. Can we stop/delete the flow files in execute script processor.
Below is the logic inside the execute script.
Created on ‎03-17-2018 06:50 AM - edited ‎08-18-2019 12:54 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@Pavan M You can use the remove method from the session object. Follows an example.
NiFi Flow
Each GenerateFlowFile processor generate an empty flow with an attributed called "a" valued 1, 2 & 3 respectively.
Script in ExecuteScript processor
flowFile = session.get() a = int(flowFile.getAttribute('a')) if(a == 1): session.transfer(flowFile, REL_FAILURE) elif(a == 2): session.transfer(flowFile, REL_SUCCESS) else: session.remove(flowFile)
So the flowFiles with "a" equalling 1 or 2 are being redirected accordingly while the others are removed. You can see that SUCCESS and FAILURE relation have 1 flow file each. The third one has been deleted.
You can modify the above script according to your business logic and you should be good.
Hope that helps!
Thanks!
Created ‎03-16-2018 06:08 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It might be easier to stop/delete the flow files before they get to the ExecuteScript processor using the RouteText processor.
Created on ‎03-17-2018 06:50 AM - edited ‎08-18-2019 12:54 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@Pavan M You can use the remove method from the session object. Follows an example.
NiFi Flow
Each GenerateFlowFile processor generate an empty flow with an attributed called "a" valued 1, 2 & 3 respectively.
Script in ExecuteScript processor
flowFile = session.get() a = int(flowFile.getAttribute('a')) if(a == 1): session.transfer(flowFile, REL_FAILURE) elif(a == 2): session.transfer(flowFile, REL_SUCCESS) else: session.remove(flowFile)
So the flowFiles with "a" equalling 1 or 2 are being redirected accordingly while the others are removed. You can see that SUCCESS and FAILURE relation have 1 flow file each. The third one has been deleted.
You can modify the above script according to your business logic and you should be good.
Hope that helps!
Thanks!
Created on ‎03-17-2018 10:08 AM - edited ‎08-18-2019 12:53 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As you are not transferring any of the flowfiles to REL_FAILURE, Transfer the else flowfiles to failure relation and auto terminate the failure relation,
else: session.transfer(flowFile, REL_FAILURE)
Auto terminate failure relation
(or)
You can use session.remove to remove the flowfile
else:
session.remove(flowFile)
by using any of the above ways you can achieve same result as you are expecting.
