Created 04-27-2016 03:12 AM
Is there a NiFi processor where I can pass a java class name, method name and arguments and get results? Similar to Hive reflect UDF.
I found ExecuteStreamCommand (which seems to do the same with OS commands) and ExecuteScript (but not sure if it's possible to call java methods using NiFi script language).
Thanks.
Created 04-27-2016 03:34 AM
To @Artem Ervits comment, if the Java class is available in the class loader (either by being part of the NiFi Core or being specified as a JAR in the ExecuteScript's Module Directory property), then you can call it directly, you don't need reflection.
If I'm not answering your question, can you provide more details? I'm happy to help 🙂
Created 04-27-2016 03:17 AM
ExecuteScript accepts Groovy, which is a jvm language.
Created 04-27-2016 03:35 AM
Thanks @Artem Ervits, yes I remember your Groovy great post for hive. Would you have and groovy example for NiFi as well?
Created 04-27-2016 04:04 AM
I'm actually posting link to Matt's blog for an example http://funnifi.blogspot.com/2016/04/sql-in-nifi-with-executescript.html
Created 04-27-2016 03:34 AM
To @Artem Ervits comment, if the Java class is available in the class loader (either by being part of the NiFi Core or being specified as a JAR in the ExecuteScript's Module Directory property), then you can call it directly, you don't need reflection.
If I'm not answering your question, can you provide more details? I'm happy to help 🙂
Created 04-27-2016 04:04 AM
Thanks @mburgess.
Imagine, hypothetically, I want to call a static method passing a string as parameter, like reserve from Apache Commons StringUtils. Would something like this work?
org.apache.commons.lang3.StringUtils.reverse( ${my_nifi_attribute} )
Created 04-27-2016 04:27 AM
Absolutely! with ExecuteScript (with, say, Groovy as the language), a script body could be something like:
import org.apache.commons.lang3.StringUtils flowFile = session.get() if(!flowFile) return flowFile = session.putAttribute('my_nifi_attribute', StringUtils.reverse( flowFile.getAttribute('my_nifi_attribute') ) session.transfer(flowFile, REL_SUCCESS)
Created 04-27-2016 04:36 AM
Awesome! Thank you.
This is much easier than writing a custom processor.
Created 04-27-2016 01:05 PM
@Guilherme Braccialli @mburgess a slightly modified version could include native Groovy reverse() method
Created 05-13-2016 03:33 PM
Hi burgess I've tried to invoke stringutils.reverse() in the same u have suggested. what the processor will propagate on successexection ? Will it propagate reversed string on success?