Addition and subtraction by day of the week

Hi @Gabriel2020 and @iCFO … Yes Java snippets are my “go to” solution for specific types of work in KNIME such as cumulative calcs.

To use them obviously basic knowledge of Java syntax is needed but beyond that, it’s simply understanding how the above “trick” works.

And it is a trick, of sorts… Java Snippets access rows one at a time from the top of the take to the bottom, and when processing each row, it can ONLY access the table data from the row currently being processed, which makes it surprising that they can be involved in cumulative calcs… so how is this possible?

Simply put they can also “remember” calculated values that were “left behind” by the previous row, provided the Java variable holding the value is defined in the section marked “your custom variables” which in this case is the “backlog” variable.

If you want to see various examples of this in action, which will hopefully assist with the understanding, take a look at this post that Iwrote a couple of years ago…

In small doses, for specific tasks such at this, basic knowledge of Java Snippets can transform your workflow.

I “discovered” this feature quite by accident. I’d been using KNIME just two months and wrote a Java snippet which had a bug in it and didn’t produce the result I expected. When I investigated further I realised it didn’t reset certain variables with each row. I nearly just shrugged it aside as something to be wary of, and then realised how useful that could be, hence the above post.

2 Likes