how to access "number of rows" for a switch?

Hi community,

depending on the number of rows in an input table I want to process differently. So I tried a "Java If (Table)" node with this condition:

if ($$ROWCOUNT$$ > 49) {return 0;}
else {return 1;}

But even for tables with only 41 rows, the If-Node returns 1.....

So I presume I have to adress the number of rows somehow differently. But how?
Can I access the currently valid table object somehow ? (e.g. this.getRowCount() ...)

Best regards and thanxx,

Susanne

P.S. btw For the "Math Formula" node ROWCOUNT is a general constant, in the other nodes it seems to be a column... so I experience a slight confusion currently....



 

 

1 Like

Hi Susanne, unfortunately the Java If (Table) not does not provide these fields, at least not yet. You need to work around the row count that you get from the Statistics node (with KNIME 2.7) or with the GroupBy node (with a fake column holding always the same value), or the Math Formula node. Just for completness there is also and empty table switch node which works together with the Java Snippet Row Filter (which would output an empty table depending on the number of given rows). Sorry, Thomas

1 Like

In fact the new very useful node called extract table dimension gives the easiest access to the table row and column number.

then use a rule engine node to define rules based on the row count, returning 0, 1, or 2 for instance. You can then convert this output to a variable with a table row to variable node and use the CASE switch node in which the switch is set by this variable of 0,1,2. You now have 3 branches on your workflow to process your data differently. At the end, merge the 3 branches back with a End CASE node.

hope this is what you are after.

simon

1 Like

Hello Thomas and hello Simon,

yep, thanks for the advice. I now solved my issue be using the "MathFormula" node, adding the ROWCOUNT as a column, then using "TableRow To Variable" node to make the row count value accessible for a "Java IF (Table)" node......

Best regards, Susanne

 

1 Like