Community Articles
Find and share helpful community-sourced technical articles
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.
Labels (1)

Some NiFi Expression Language (EL) expressions can be fairly complex, or used in a large flow, or both. These can make it difficult to test an EL expression on a running NiFi system. Although an excellent feature of NiFi is being able to adapt the flow while the system is running, it may not be prudent to stop a downstream processor, reroute a connection to something like UpdateAttribute, then list the queue in order to see attributes, content, etc.

To make EL testing easier, I wrote a Groovy script called testEL.groovy that uses the same EL library that NiFi does, so all functions present in the specified NiFi version are available to the test tool. The following is the usage:

usage: groovy testEL.groovy [options] [expressions] 
Options:  
 -D <attribute=value>   set value for given attribute
 -help                  print this message

As an example, the following tests an expression that appends "_world" to the "filename" attribute:

> groovy testEL.groovy -D filename=hello '${filename:append("_world")}' 
hello_world

Note that it accepts multiple attribute definitions and multiple expressions, so you can test more than one expression using a single set of attributes:

> groovy testEL.groovy -D filename=hello -D size=10 '${filename:append("_world")}' '${filename:prepend("I say "):append(" ${size} times")}'

hello_world
I say hello 10 times

In order to attach testelgroovy.txt to this post, I had to add a .txt extension (and it lowercased the name), simply rename it before running the above.

Hopefully you find this script helpful, if you try it please let me know how/if it works for you, and as always I welcome any questions, comments and suggestions on how to make things better :)

Cheers!

1,563 Views
Comments
Not applicable

Hi, i think that testing the expression language using the command line it is a very fast and convenient way to test expressions.

However, trying to run your script i encountered an error caused by a maven dependencies not resolved. This is the error that i'm encountering:

General error during conversion: Error grabbing Grapes -- [download failed: com.fasterxml.jackson.core#jackson-annotations;2.6.0!jackson-annotations.jar(bundle)]

Don't have an account?
Coming from Hortonworks? Activate your account here
Version history
Revision #:
1 of 1
Last update:
‎10-25-2017 08:57 PM
Updated by:
 
Contributors
Top Kudoed Authors