Created 02-13-2017 05:24 PM
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
Created 02-13-2017 06:44 PM
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.
Created 02-13-2017 05:33 PM
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
Created 02-13-2017 05:38 PM
@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.
Created 02-13-2017 06:48 PM
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
Created 02-13-2017 06:23 PM
@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}}
Created 02-13-2017 06:44 PM
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.
Created 02-14-2017 02:17 PM
This works! Explained very clearly. Thanks!