Q:

how to take flowfile count in nifi queue?

i have nifi flow(standalone) like 
executestreamprocessor(hive script) -> executestreamprocessor(hadoop script).

for each and every incoming flowfile, hive script runs with the command INSERT..INTO..SELECT..FROM and hadoop script deletes the particular files from the storage area.
sometimes, hive script is getting failed when simultaneously hadoop script runs the command.
i will be getting maximum of 4 number of files for each an hour. so i planned to use controlrate processor in between the hive and hadoop processors. i set the condition when count of the queue reaches to 4 flowfile, then hadoop script should be executed. But, controlrate has the property to set only for maximum rate. it does not have minimum rate.
is there any possible solution to achieve? or any other solution?

A:

You should be able to use ExecuteScript for this, try this Groovy script:
def flowFiles = session.get(4)
if(!flowFiles || flowFiles.size() < 4) {
  session.rollback()
} else {
  session.transfer(flowFiles, REL_SUCCESS)
}

If you only want to trigger the downstream flow once, then you can create a child flow file from the parents (and report a JOIN provenance event):
def flowFiles = session.get(4)
if(!flowFiles || flowFiles.size() < 4) {
  session.rollback()
} else {
  def flowFile = session.create(flowFiles)
  session.provenanceReporter.join(flowFiles, flowFile)
  session.remove(flowFiles)
  session.transfer(flowFile, REL_SUCCESS)
} 

Having said that, if you don't care about the flow file contents (i.e. you are using a flow file as a trigger), you could use MergeContent with a Minimum and Maximum Number Of Entries = 4.

