I have a Knime Java simple node, where I’m trying to put some simple Number logic if a column is null, However, Knime is unable to identify the null columns in Java.
The column’s data type is Long and I tried with .equals(null) , ==0.0f , ==null.
None of them works.
Please help if anyone has faced similar challenge or any work around.
Hi @sujitnath84
just to be sure, did you check this checkbox of the Java Snippet Simple node?
Best
Aswin
Yep @Ashwin, That’s done already
@Aswin , strange but I unchecked and checked , ran again and it seems to work. What the heck!! Not sure if this is a bug or what…
Hi there @sujitnath84,
glad you made it. If it happens again and you manage to figure out steps to reproduce feel free to share it and someone will check it
Br,
Ivan
@Aswin @ipazin Is there a way in which I can hold the value of previous column in Knime using Java. I tried using the lag node in between, but it does not solve my purpose.
I want to store the value of previous value of a column “A” and on certain conditions, use that value.
Dear @sujitnath84
Knime is very “row focussed”, most operations such as the Math node and the String Manipulation node operate on single rows only, that’s how Knime can work with large tables efficiently. The downside is, that you cannot easily access cells in other rows like you would in Excel. I can think of two solutions:
- The lag node can (unfortunately) lag only in one direction, maybe that is your problem. To use the lag node anyway, use the Sorter node to flip the table upside down. You may need to create an index column first, you can do this with a Math node.
- Use the moving aggregation node, like this:
It will generate a new column that contains the previous values of the elements in the initial column.
Good luck!
Aswin
Hi @Aswin, Using the moving aggregation row, I get some partial task fullfilled. Now the issue is, Suppose a column has repeating values some null etc, The new column will copy the value till the specified intervals.
However, what I want is, when the value of my column changes, the generated column must also change the value and it must carry the new value, rather than copying the old value.
Hi there @sujitnath84,
don’t get me wrong but think it is about time you tell us more about your use case and provide some input data and desired output so you can get proper ideas/solutions
Br,
Ivan
@ipazin ,
Attached is the desired table snapshot. Here the logic goes like –
if ( (ID1 = ID2) AND FLAG is NULL ) ==> Previously stored value of result column shoull show in result
else ( Value of FLAG should be stored in result )
So, at the first row, ID1 <> ID2, so result will be FLAG value, ie. null
2nd row, ID1=ID2 AND FLAG is null, so the result value will be the current value of result in memory (in this case, the value of result in first step)
… and so on. Let me know if I can clarify more.
Thanks!!
Hi there @sujitnath84,
for this kind of use cases I would go with scripting. You can use Column Expressions node with following syntax:
if (and((column("ID1") == column("ID2")), isMissing(column("Flag"))) ){
res;
}
else{
column("Flag")
res = column("Flag");
}
Although this works on your example haven’t tested it thoroughly.
Br,
Ivan
Hi @ipazin, I’ve got the solution to this using the java simple node. I created a global static String variable, and did not initialize it. Later I inserted the values according to the condition to that into that Global variable.
When the code would go to next row, the value will be retained.
The moving aggregation was out of picture. It was an easy solution, just the thought process did not click fast
Thanks alot for the help & efforts.