Created on 12-09-2019 11:36 AM - last edited on 12-09-2019 01:22 PM by cjervis
Hello, I want to perform a simple mathematical operation on a json attribute.
I simply want to subtract 30 from the value.
Any help would be appreciated
Created 12-09-2019 12:42 PM
my initial thought here for you would be to chain the following three NiFi processor components together:
--> EvaluateJsonPath ---> UpdateAttribute ---> UpdateRecord -->
1. The EvaluateJsonPath processor should be configured to write the desired Json field value out to a NiFi FlowFileAttribute.
2. The UpdateAttribute processor would be used to manipulate that extracted value by subtracting 30 from it using the NiFi Expression Language (EL)
3. The UpdateRecord processor would be used to update your original FlowFile JSON content with the new Json field value.
Hope this helps you,
Matt
Created 12-10-2019 09:14 AM
Hey Matt, thank you so much
I've set up that flow but I'm having trouble on the actual updateattribute function I'm applying:
${COUNTFILES:minus(31)}
I'm using this and it's not modifying the value.
Could you please help?
Created 12-10-2019 09:38 AM
Out of your EvaluateJsonPath processor your FlowFile now has an attribute with the name "COUNTFILES" and a numeric value? You can confirm this by stopping the UpdateAttribute processor and allowing a test FlowFile to queue on the connection between EvaluateJsonPath and UpdateAttribute processors. Then right click on connection and select "list queue" from the displayed context menu. Then click on the "view details" icon to the far left of row for your listed FlowFile. Within the FlowFile details UI you can inspect the attributes set on this FlowFile.
Then start only the UpdateAttribute processor while UpdateRecord is still stopped and repeat above to verify that updateAttribute processor modified the attribute value.
Matt
Created 12-10-2019 10:45 AM
So it's part of the flowfile content. I attached the flow and the configs.
Sorry for the confusion if I caused any
I'm using a count
Created 12-10-2019 11:21 AM
Writing to the content will overwrite all the other content which is not what I think you want to be doing. Plus the updateAttribute processor can only manipulate FlowFile attributes via the NiFi Expression Language (EL).
So you need to extract the json value to a FlowFile attribute in the EvaluateJsonPath processor. Then manipulate that attributes value and then use UpdateRecord to update the actual content of your FlowFile using that FlowFile's attribute.
Matt
Created 12-10-2019 01:12 PM
I'm okay with writing over the content of the rest of the file.
I'm trying to output the rowcount results in a putemail so I'm okay with overwriting the rest of the flowfile.
Can you still help with this?
Created 12-11-2019 11:06 AM
No problem. At this point you have extracted the the count successfully and used updateAttribute processor to subtract 31 from it. You do not need to write it back to the content to use it in putEmail processor.
The majority of the putEmail processor configuration properties support NiFi Expression Language also.
You can retrieve the value of your FlowFiiles attribute with this simple NiFi EL statement:
${COUNTFILES}
So you can use above anywhere in the string you configure in the the "Subject" and/or "Message" configuration properties.
Thanks,
Matt
If you found my answer help you to a solution, please don't forget to mark it as the accepted solution.