Support Questions

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

Setting: Stateful Variables Initial Value in UpdateAttributes

New Contributor

I would like to use the the local State Management to keep track of the maximum value of a FlowFile attribute ever seen (the last data I fetched from an HTTP endpoint). It seems the UpdateAttributes "Store State" feature could be useful in keeping track of the maximum date I have processed thus far.

However, I can't even get the example in the UpdateAttributes documentation to work:

  • Dynamic Property
    • key : theCount
    • value : ${getStateValue("theCount"):plus(1)}

I've set "Store State" to "Store state locally" but don't know how to set "Stateful Variables Initial Value".

When running the attribute "theCount" shows up as empty.

I tried changing the "value" to: ${getStateValue("theCount"):toNumber():plus(1)}

But that doesn't help. How is one supposed to use "Stateful Variables Initial Value"?


Master Guru

Have you tried setting "Stateful Variables Initial Value" to 0 for the example?

What it should be doing is taking all the names of the dynamic properties (in this case "theCount") and creating an initial map of names to initial value, so you should end up with a map that has theCount -> 0 and then when the processor runs it would increment from 0 to 1 on the first execution.

New Contributor

Hi Brian, thanks for your reply.

"Have you tried setting "Stateful Variables Initial Value" to 0 for the example?"

I'm not sure how to do that. I would have expected the web UI to link to a tabular attribute-setting widget for the "Stateful Variables Initial Value" in the NiFi web UI but it takes a text value. Further its text field says "Supports expression language: false" so I don't see how to create a map or map entry using the text field. [I don't know what the expression language syntax would be for creating a map or adding an entry to a map even if it did. I tried various (made up) guesses, for example, ${theCount.set(0)} but not surprisingly it didn't work.]

I'm sure I'm missing something but I haven't even been able to even find a template XML on the web that sets "Stateful Variables Initial Value" to see an example.

Master Guru

I don't know the history behind the state support in UpdateAttribute, but I looked at the code earlier and it looks like it expects "Stateful Variables Initial Value" to just be a single value, which means it would be the same value for all variables. So if you literally enter 0 for the value of that property in the UI, it should initialize all variables to 0.

New Contributor

I gave setting that text field to 0 a try. It made no difference. I am using LogAttribute to log the attributes before and after the UpdateAttribute and the one before the UpdateAttribute never shows the attribute "theCount". The one after UpdateAttribute shows:

FlowFile Attribute Map Content
Key: 'filename'
	Value: '6904754831116'
Key: 'theCount'
	Value: ''
Key: 'path'
	Value: './'

New Contributor

I Ran into this issue today... After 1 hour deleted the processor and started over and then it was working fine... No idea what happened. FYI for link to guide look here: