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

ExecuteScript errors / alternative ways to compare two seperate flow files in nifi


ExecuteScript errors / alternative ways to compare two seperate flow files in nifi

New Contributor

Hi, very junior developer new to nifi and using groovy.

The goal I'm trying achieve is I have a csv file which holds data on what files need to be processed. My flow files consists of all the files that are coming in from a TCP stream and I need to compare the csv with these to then route them in specific directions. I first tried to do this extracting the csv and using update attribute but then got stuck as the csv and data files had different attributes. After finding the scripting cook book and matts blog which has helped a mile. I've managed to make this script which does pull out the correct files (when using local test data with some lines commented out) but I've yet to get it to work in nifi

//get flow file

def flowFile = session.get()

if(!flowFile) return

flowFile = session.write(flowFile, {inputStream, outputStream ->

// get task file

def taskCSV = new File('D:/Tasking/task.csv').getText()

def taskedValues = []

def taskedRegex = []

//extract values from CSV, place into taskedValues

taskedValues = taskCSV.tokenize(", ") //copy values into taskedRegex and transform into regular expressions

taskedRegex = taskedValues taskedRegex.each{ it = ~it //~ makes creates a regex. it is "this" element }

//loop through taskedRegex use it to extract values from flowfile filenames


def matcher = (flowFile.getAttribute('filename') =~ it) // log it here..

// putAttributes of if they are matched.

if (matcher.matches()){ flowFile = session.putAttribute(flowFile, 'isTasked', 'true') } }

//send success relationship

session.transfer(flowFile, REL_SUCCESS) })

I've tried to find the full stack trace but I'm not sure where it lives. Here is an image of the error.


Apologies for such a large essay. Any help is much appreciated.



Don't have an account?
Coming from Hortonworks? Activate your account here