Created on 08-09-2018 01:12 AM - edited 09-16-2022 06:34 AM
Newbie here. I'm attempting to utilize multiple string manipulation operations for an attribute that has been passed into one of my processors. Specifically, I have the following where I am referencing an attribute value:
/Absolute/Directory/Path/${path:substringAfter('FruitBasket')}
where the expression could have the hypothetical values of:
"/store/produce/FruitBasket/RedFruits.txt"
"/store/produce/FruitBasket/YellowFruits.txt"
"/store/produce/FruitBasket/OrangeFruits.txt"
I am attempting to replace the ending substring WITHIN the string returned from the expression above as such:
/Absolute/Directory/Path/${path:substringAfter('FruitBasket'):replace('RedFruits.txt', 'Apple1.txt')}
or
/Absolute/Directory/Path/${path:substringAfter('FruitBasket'):replace('YellowFruits.txt', 'Banana2.txt')}
etc..
So that I get:
"/Absolute/Directory/Path/Apple1.txt"
or
"/Absolute/Directory/Path/Banana2.txt"
However, when I do this, I actually get the literal value of:
"/Absolute/Directory/Path/${path:substringAfter('FruitBasket').replace('RedFruits.txt', 'Apple1.txt')}"
Under the section describing the NiFi expression language in https://docs.hortonworks.com, it says we can "chain together multiple function calls". However, I'm unsure of whether this works for string manipulations. Just to check, I reversed the order of chaining and performed the replace BEFORE the substringAfter and still got the same behavior. Additionally, I tried performing the replace alone, and apparently it did not like the embedded numbers. Can anyone shed any light this or present a viable alternative solution? Thank you.
-Jay
Created on 08-09-2018 03:20 PM - edited 08-17-2019 08:11 PM
@Jay C
-
What you are trying to do is supported by NiFi Expression Language (EL).
Your "literal value" example output show a "." instead of ":" before replace.
What processor are you using this EL statement in? Not all processor properties support NiFi expression language. Floating your cursor over the small "?" circle next to a property will produce a pop-up that will tell you if EL is supported:
-
Using the updateAttribute processor you would add a dynamic property with your EL statement as follows:
-
After the FlowFile passes through the updateAttribute processor and i look at the attributes on the file listed in the output queue, I see:
-
As you can see the value from the "path" variable on the source FlowFile was used and the output is correct based on how the EL statement was written.
***Note: you may want to include the "/" in your substringAfter or drop the "/" at the end of "/Absolute/Directory/Path/" or instead use the "substringAfterLast('/')" in your EL statement instead to avoid the double "//" in the result.
-
Thanks,
Matt
-
If you found this Answer addressed your original question, please take a moment to login and click "Accept" below the answer.
Created 08-15-2018 04:28 PM
-
If above did not resolve your issue. Providing some screenshots of your processor configuration may be helpful in pointing out where the issue is.
-
Thanks,
Matt