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

為{幸葍}努か 提交于 2020-01-04 09:14:51

问题


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?


回答1:


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();


来源:https://stackoverflow.com/questions/47517720/in-apache-nifi-can-i-evaluate-expression-language-without-an-attribute

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!