I have a table of users and their parents.If the parent is 0, this parent is the top parent of a group. I want to calculate to have for each user, his/her top parent.
Parent of 1 is 3, but 3 is not a top parent as its parent is 4. 4 is neither a top parent as its parent is 5, which is the top parent. So, top parent of 1 is 5.
2 is the parent of 6 (the last row of the input table) and we know that 2 is a top parent as it is marked as 2 | 0 at the second row of the input table. So 2 is the top parent of 6 (in this case, the unique parent)
3 is parent of 1, and 4 is parent of 3, and 5 is parent of 4 and 5 is a top parent
So, reverse hierarchy would be 1,3,4,5, is that correct? Is that how the hierarchy is determined?
EDIT: If I’m correct in the logic, then this can be done via a Recursive Loop.
I need to step out at the moment. If you have not determined how to implement this, I’ll do it later.
Hi @jquadrada , I’m back. I see what @aworker has provided solution, which is good enough.
@aworker , originally I had wanted to use H2 as a virtual table that would allow me to set some values and update them within the loop. It looks like it’s no necessary based on what you did
Thanks for your help here. I’m always impressed by your solutions to so many different KNIME questions!
Sorry, I did not understand what you meant here by “to use H2”. Could you please develop ? May be you could add here this alternative solution too.
Regarding your question about H2, manipulating values in a table and keeping these new values within loops in Knime is quite tricky, so my idea was to use a virtual db table instead where I could update values in the db table at every iteration of the loop, and H2 is the best way to do this as it can generate the db connection and create a table in memory.
However, with the Recursive Loop, it was not necessary, since the Recursive Loop allows you to pass on the “new” values to the next iteration.
How about simply a Cell Replacer within Recursive Loop? Also stop criteria is probably a good idea so you don’t have to run large number of iterations to be sure you’ll find parent.