在Apache NiFi中,我可以在没有属性的情况下评估表达式语言吗? [英] In Apache NiFi, can I evaluate expression language without an attribute?

查看:177
本文介绍了在Apache NiFi中,我可以在没有属性的情况下评估表达式语言吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,在自定义处理器中,我可能希望仅对字符串"$ {UUID()}"中的表达式求值(仅作为示例).

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?

推荐答案

在自定义处理器(或脚本处理器)中

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

这篇关于在Apache NiFi中,我可以在没有属性的情况下评估表达式语言吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆