Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

NiFi dynamic properties (UpdateAttribute) - is it possible?

avatar
Contributor

Hi,

I have two types of properties:

> 1st fixed one ("suffix") and

> 2nd "nifi.prefix.[suffix]" - set of defined properties where suffix is a value of 1st property

Let's assume that I'd like to set the value of "nifi.filename" dynamically to nifi.prefix.[suffix], where suffix is a value of "suffix".

If "suffix" resolves to "cat", "nifi.filename" should be assigned a ${nifi.prefix.cat} property value.

Something like below unfortunatelly does not work:

nifi.filename = ${nifi.prefix.${suffix}}

Do you know if there are any workarounds so that I can achieve what I need?

Thanks, Michal

1 ACCEPTED SOLUTION

avatar
Master Guru

For this, I am assuming that you have a property called "nifi.prefix.cat" defined in your Variable Registry (custom.properties, e.g.):

nifi.prefix.cat=my_filename.txt

Then assuming a flow file comes into UpdateAttribute and has the "suffix" property set to "cat", you can add a dynamic property called "nifi.filename" set to:

${${literal('nifi.prefix.'):append(${suffix})}}

This should give you an attribute called "nifi.filename" set to "my_filename.txt". Please let me know if I've understood what you are trying to do, and I'll edit this as needed.

View solution in original post

6 REPLIES 6

avatar
Super Mentor
@Michal R

I believe what you are trying to do is take two key/value pairs assigned as FlowFile Attributes to an incoming FlowFile and merge them together to form a new filename.

${nifi.prefix}.${suffix}

Assuming your incoming FlowFile has the following attributes:

nifi.prefix=myfile
suffix=cat

The result from the above NiFi Expression Language statement would be:

myfile.cat

Thank,

Matt

avatar
Contributor

@Matt Clarke, no you have not understood my problem - I would like to get a value of a property (e.g. from custom.properties file) called ${nifi.prefix.cat}. nifi.prefix is a literal. The thing is I would like to construct this property name dynamically.

avatar
Super Mentor

@Michal R

I think I understand now.

You have a FlowFile that contains an attribute "suffix" with some value assigned to it. Let's assume that is "cat" for now.

You have a registry file that contains a bunch of key value pairs for things like "nifi.prefix.cat", "nifi.prefix.dog", etc...

Now you want to be able to return the value of "nifi.prefix.cat".

In that case, you would use the following EL statement in your UpdateAttribute processor:

${${suffix:prepend('nifi.prefix.')}}

The first input to an EL statement is the subject. The function is then applied against the value returned for that subject.

Thanks,

Matt

avatar
Super Collaborator

@Michal R do you have a attribute myfile.cat=somevalue where nifi.prefix=myfile and suffix=cat , in the flow file, that you want to retrieve? you are trying to retrieve the value myfile.cat and assign it to nifi.filename? ,i am not sure if EL can be nested like you did. But you can try doing instead of what you did ... nifi.filename = ${${nifi.prefix}.${suffix}}

avatar
Master Guru

For this, I am assuming that you have a property called "nifi.prefix.cat" defined in your Variable Registry (custom.properties, e.g.):

nifi.prefix.cat=my_filename.txt

Then assuming a flow file comes into UpdateAttribute and has the "suffix" property set to "cat", you can add a dynamic property called "nifi.filename" set to:

${${literal('nifi.prefix.'):append(${suffix})}}

This should give you an attribute called "nifi.filename" set to "my_filename.txt". Please let me know if I've understood what you are trying to do, and I'll edit this as needed.

avatar
Contributor

This works! Explained very clearly. Thanks!