Sorting on RowID

I keep forgetting to raise this issue I sometimes get in workflows.

after various manipulations my table has often lost its original order, I.e. The RowIDs are no longer in their original order.

there is no node which can easily sort this out, ideally a Sort By RowID node is required. Which can intelligently sort on mixed text and numbers, I.e. Such that Row0, Row1, Row2, .... Row 10, Row11, .... Row100 appear in this order etc. and not Row0, Row1, Row10, Row2 ....

i appreciate there are some workarounds that can be done, such as using a Maths formula node to generate a ROWINDEX column, earlier in the workflow, then sort on this ROWINDEX column, but this is not always practical when certain manipulations are done, and it's fiddly and cumbersome.

any thoughts?

simon.

I agree, this would be quite nice.  Maybe a feature request for the sorter node (sort by RowID)?

 

 

Simon,

Fully with you, the legacy "RowID as messed-up string" is quite annoying. A (hidden?) rowindex in the default table model would be quite a thing to have for sorting (and joining?) purposes. 

Cheers
E

The hidden rowid sorting will break as soon as you concatenate two tables, because then these hidden rowIds won't be unique any more and don't really correspond to the visible row IDs any more. Also there may be other row ids, not generated by KNIME that have a similar format (i.e. "string"+"number").

We (actually Bernd ;-)) were thinking of the following solution for sorting:

  • The row id will be split into a string part at the beginning and an number part at the end
  • When comparing two row IDs, first the string part will be compared lexicograhically, and then the number part
  • If any part is missing in a row ID it will be treated as the empty string or -infinity i.e. smaller than any existing string or number, respectively.

Some examples:

ARow0
ZRow1
BRowNoNumber
112
ARow0
ZRow11
ZRow2
27

will be sorted as

27
112
ARow0
ARow0
BRowNoNumber
ZRow1
ZRow2
ZRow11

But also

Row3
Row4
Row22_1

would be sorted as

Row22_1
Row3
Row4

Does this come close to your expectations?

Hey all,

good things come to those who wait: on behalf of our developers (praise goes to @hotzm !), I’m happy to announce that a alphanumeric sort order has been implemented in the sorter node, the table view, and most other places where sorting is done. Check it out in the new KNIME Version 4.7.1! Of course, backward compatibility is not broken, so e.g. the GroupBy/Pivot Nodes still sort strings the old fashioned way. Also, this was already available in 4.7.0 in case you didn’t notice :slight_smile:

Kind regards,
Lukas

5 Likes

Brilliant. Great things come to those who wait !!

2 Likes

Hi Lukas,
First of all my compliments for the improvement on the alphanumeric sort order option in the sorter node!
Unfortunately I faced an issue when using flow variables that was not there before.
I used the inclList and sortOrder variables but got an error after the upgrade. this was caused by the variable alphaNumStringComp field that was empty. Easiest for me was to use the variable I use for the sortOrder because this is also a boolean list variable, with the correct amount of arguments.

Kind regards, Jan.

1 Like

Hi guys,

Today, knime have 2 improve nodes…

Tip 1 - you can use the rowID to generate a new id and append the info to columns.

Tip 2 - You can use the sort node now to sort by row id too.

So the problems were solved about it…

Tip 3- At the beginning, you can add a counter node/rank node to add number for each row as a flag. Any time that you need, you can use it to reorder all the table again as the first modification, can it help you?

BR,

Denis

Hi @Jankr,

thank you very much for reporting the issue! Indeed, I can confirm this bug. I’m glad you already figured out a way to work around the problem – nonetheless I forwarded this, and it will be be fixed by adding a default-array of false entries, so that the node will continue to work with flow variables configured.

(and sorry for the late response – thanks @denisfi for taking over in the meantime)

All the best and thanks again,
Lukas

4 Likes

Hi @Jankr,

thank’s again for reporting the bug! We released the fix (AP-20588) as part of AP 4.7.8 and 5.2.0 (and to-be-released 5.1.3).

3 Likes