Premising that I’m not expert of JAVA programming, I tired to use KNIME AI Assistant and with his suggestion I write the below code in order to do the following operations on a dataset composed by two columns:
sorting the dataset according column Count(ID) (descending value);
truncate the data set according the following criteria: cumulative sum of Count(ID)/Sum of all Count(ID) elements >=0,8.
I don’t fully understand why this code doesn’t work.
Hi @Guglielmo , I haven’t tried looking at the suggestions that the AI assistant will make for java snippets, but the code won’t work because unfortunately this is not the way java snippets work.
Take a look at the first 5 paragraphs of the following post which apply equally here, and gives some background about why it won’t work…
The java snippet can only process a single row at a time and is called once for each row in the dataset, sequentially.
A java snippet therefore cannot access all rows at the same time in a single invocation. It cannot sort the rows and it is not capable of either increasing the number of rows or reducing the number of rows in the resultant dataset.
It is a powerful node but not suitable for the type of operations you are trying to perform. The python nodes, on the other hand, can do all those things. I hope that helps.
There are some things that it can do though to assist with cumulative calculations though… See
Many thanks for explanations. In addition to the post that you have linked, do you know if there is any tutorial or other documentation available on the KNIME web-site where is exhaustively explained as Java Snippet nodes works. It is not the first time that I make experience that the Java /Java Script codes cannot be implemented in Java snippet nodes as per “standard” programming so it could be helpful to understand all the limitations and differences that exists in coding when you work in KNIME environments.
Thank you very much.