rich
rich

Reputation: 19405

In Apache NiFi, can I evaluate expression language without an attribute?

For instance, in a custom processor I may wish to evaluate simply the expression in the String "${UUID()}" (just as an example).

I don't want to expose an attribute to the user, I just want to evaluate the expression. Can I do that?

Upvotes: 3

Views: 3423

Answers (1)

daggett
daggett

Reputation: 28564

in a custom processor (or script processor)

import org.apache.nifi.components.PropertyValue;
...
String expression = "${UUID()}";
PropertyValue myValue = context.newPropertyValue( expression );

in this case it's enough to call this to evaluate expression because no dependency on other attributes in expression itself:

String result = myValue.evaluateAttributeExpressions().getValue();

but if you use attributes in expression:

Map<String, String> attributes = ...;
String result = myValue.evaluateAttributeExpressions(attributes).getValue();

or if all required attributes in a flowfile:

String result = myValue.evaluateAttributeExpressions(flowFile).getValue();

Upvotes: 7

Related Questions