- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Nifi - Java Reflection Processor
- Labels:
-
Apache NiFi
Created 04-27-2016 03:12 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ExecuteScript accepts Groovy, which is a jvm language.
Created 04-27-2016 03:35 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Awesome! Thank you.
This is much easier than writing a custom processor.
Created 04-27-2016 01:05 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@Guilherme Braccialli @mburgess a slightly modified version could include native Groovy reverse() method
Created 05-13-2016 03:33 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
