在 Apache NiFi 中,我可以评估没有属性的表达式语言吗?
In Apache NiFi, can I evaluate expression language without an attribute?
例如,在自定义处理器中,我可能希望简单地评估字符串“${UUID()}”中的表达式(仅作为示例)。
我不想向用户公开属性,我只想计算表达式。我可以这样做吗?
在自定义处理器(或脚本处理器)中
import org.apache.nifi.components.PropertyValue;
...
String expression = "${UUID()}";
PropertyValue myValue = context.newPropertyValue( expression );
在这种情况下,调用它来评估表达式就足够了,因为表达式本身不依赖于其他属性:
String result = myValue.evaluateAttributeExpressions().getValue();
但是如果你在表达式中使用属性:
Map<String, String> attributes = ...;
String result = myValue.evaluateAttributeExpressions(attributes).getValue();
或者如果流程文件中的所有必需属性:
String result = myValue.evaluateAttributeExpressions(flowFile).getValue();
例如,在自定义处理器中,我可能希望简单地评估字符串“${UUID()}”中的表达式(仅作为示例)。
我不想向用户公开属性,我只想计算表达式。我可以这样做吗?
在自定义处理器(或脚本处理器)中
import org.apache.nifi.components.PropertyValue;
...
String expression = "${UUID()}";
PropertyValue myValue = context.newPropertyValue( expression );
在这种情况下,调用它来评估表达式就足够了,因为表达式本身不依赖于其他属性:
String result = myValue.evaluateAttributeExpressions().getValue();
但是如果你在表达式中使用属性:
Map<String, String> attributes = ...;
String result = myValue.evaluateAttributeExpressions(attributes).getValue();
或者如果流程文件中的所有必需属性:
String result = myValue.evaluateAttributeExpressions(flowFile).getValue();