Extract list index while/before ungroup

Hey :slight_smile:,

I have a table with one column of lists, which have different lengths, I need to ungroup them but also have to save the Index of the values, so I can later identify the object in the list and maybe change it.
Right now I do this with a Chunk Loop with size 1, inside the loop I add a column with the RowIndex to table using a Rule Engine Node. I am however not 100% percent sure if this will work as I don’t know how the ungroup Node is implemented. Would be nice if someone can tell me if this is a safe implementation or if there is a more efficient way of doing this.

Thanks! image

Hi there @tbtt,

seems to me what you have done will work just fine. Might not be efficient in case of many rows so here are two suggestions you can try to implement:

  • create additional list column holding indices. So for list [15,25,35] you will have [1,2,3] - this might be a bit tricky but if you know Java/JavaScript/Python think shouldn’t be a problem. Then with single Ungroup node you are done
  • use Counter Generation node to create unique ID per every list. Ungrouping your data will lead to each member having same ID. Then again using Counter Generation node inside Group Loop Start node will do the trick. Still loop approach but less iterations for sure.

Hope this helps!

Br,
Ivan

Your first suggestion seems like a good idea for me!
If you recommend this solution perfomancewise of the three options I would give it a try, the list should be in most uses cases between 0 and 10 elements while the number of rows can go up to over 1000.

I guess you recommend Java performance wise? :unamused:

Thanks for your input! :slight_smile:

Hi @tbtt,

Yes. This really seems like a job for while/for loop which runs until counter reaches list length while adding this same counter into new list.

Feel free to share you solution here. I’m interested as I ran into some problems with JavaScript in Column Expressions node.

Br,
Ivan

Hey Ivan,

this is my code:

if (c_exceptional_openingss != null)
{
int len = c_exceptional_openingss.length;
Integer array = new Integer[len];
for (int i=0; i<len; i++)
{
array[i] = i;
}
out_index_array = array;
}

Was struggling quite a bit, mostly due to my miserable Java knowledge and due to the point that KNIME told me, that an exception was thrown and I should look in the log for more details, but couldnt find any log with details.
However it seems to work now. I couldnt make it with adding the indizes directly to the output array which is because of the variable scope I guess?

Thanks!

1 Like

A post was split to a new topic: Optimizing string matching within lists

Hi there @tbtt,

glad you made it. I found a way using Column Expressions as well.

Not sure why exception was thrown (probably more miserable Java knowledge here) but log is located in following location: ...\knime-workspace\.metadata\knime\knime.log (log verbosity can be defined in File--> Preferences --> KNIME).

New question moved to another topic. (Not so related to original question, will get more visibility and keep our forum tidy).

Also behind three dots in each reply there is Solution button which you can hit if topic solved. (Will help others, close topic earlier and again keep our forum tidy :slight_smile: ).

Br,
Ivan

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.