Created on 10-25-2017 08:57 PM
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!
Created on 12-17-2017 05:30 PM
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)]
Created on 06-17-2020 01:56 AM - edited 06-17-2020 01:57 AM
Me too. Similar error.
java.lang.RuntimeException: Error grabbing Grapes -- [download failed: org.apache.commons#commons-lang3;3.5!commons-lang3.jar]
Created on 06-17-2020 02:05 AM
I fixed this by changing the @Grab in the first line of the script to the following;
@Grab(group='org.apache.nifi', module='nifi-expression-language', version='1.11.4')
Created on 08-21-2020 08:32 AM - edited 08-21-2020 08:33 AM
Greetings. I tried the provided testelgroovy.txt unchanged and also with nifi-expression-language 1.11.4 to no vail. Here is the error I get no matter what expression I try:
$ groovy testelgroovy.txt -D filename=hello '${filename:append("_world")}'
Caught: org.apache.nifi.attribute.expression.language.exception.AttributeExpressionLanguageParsingException: Unexpected token '<EOF>' at line 1, column 0. Query:
org.apache.nifi.attribute.expression.language.exception.AttributeExpressionLanguageParsingException: Unexpected token '<EOF>' at line 1, column 0. Query:
at org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.displayRecognitionError(AttributeExpressionParser.java:191)
at org.antlr.runtime.BaseRecognizer.reportError(BaseRecognizer.java:186)
at org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.expression(AttributeExpressionParser.java:3898)
at org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.query(AttributeExpressionParser.java:3937)
at org.apache.nifi.attribute.expression.language.compile.ExpressionCompiler.compile(ExpressionCompiler.java:231)
at org.apache.nifi.attribute.expression.language.Query.compile(Query.java:293)
at org.apache.nifi.attribute.expression.language.Query$compile.call(Unknown Source)
at testelgroovy$_run_closure2.doCall(testelgroovy.txt:25)
at testelgroovy.run(testelgroovy.txt:24)
$ groovy --version
Groovy Version: 3.0.4 JVM: 1.8.0_242 Vendor: OS: Windows 10
P.S. I run this test under Cygwin.
Created on 07-22-2021 03:08 PM
cool tool. I updated to work with 1.12.1: https://gist.github.com/tpanagos/fb8ca4afb16b00862429ffc87dc65348