Search code examples
apache-nifi

Nifi reset counter varible using UpdateAttribute at runtime


Have a flow that is SFTPing files to a remote host. Id like these files to go different directories on the host based on value of counter.

So PutSFTP has RemotePath value of "/input_data/${counter}"

Before PutSFTP is an UpdateAttribute processing setting the value of counter to which is just incremented by one on each flowfile.

However, in UpdateAttribute, is it possible to reset counter to 0 or 1 when it reaches a certain value? Say when "counter" reaches 5, reset to 0


Solution

  • Try with modulo function:

    Name: counter
    Value: ${counter:isEmpty():ifElse('0', '${counter:toNumber():mod(5):plus(1)}')}
    

    So that when the value reaches 5, it will reset to 0 on the next file.