Loop through rows in table?! I'm confused...

OK, I’m sure the answer is simple, but sadly I just don’t “get it”. I’m a programmer from the early '80s, but I’m having trouble getting the “concept” behind how KNIME processes rows in a table.

For example, in SQL, a single SELECT statement processes a whole group of rows at the same time. Something like SQL Server T-SQL, or Microsoft VBA (Microsoft Access) lets you process a row at a time.

How do I process one row at a time in KNIME?

Conceptually, I want to “loop” through all the rows in a table (perhaps 1,000 rows), and examining each row individually, update the rows, and save them in a new table.

For example, say I have a table “Table A”, with rows:
NAME VALUE RESULT
X 1
Y 2
Z 3

Note: I had trouble formatting the table above. The letters should be in the “NAME” column, the numbers, in the VALUE column, with RESULT column blank (what I want to update in a KNIME workflow).

I want to process the rows of “Table A”, create a new table (“Table B”), with the RESULT column being a function of the VALUE column (perhaps VALUE*2). This is an artificial example, but hopefully you get the idea.

This grizzled old C, Java, SQL, FORTAN, assembler, VBA programmer is confused
…I can’t tell if I just:

  • Connect nodes sequentially (no loop)?
  • Use a loop?
  • Use a recursive loop?

I have both the Beginner’s Luck and Advanced Luck books, but I’m just missing the “concept” of how KNIME does this. Oddly enough I’ve been able to do other workflows OK, but the above is really confusing me!

Many nodes implicitly process one row at a time. If you want to explicitly process each row separately, you can use a loop starting with a Chunk Loop Start node, with the chunk size set to one. End the loop with a simple Loop End node, and the results of each iteration will be added to the bottom of the results table.

You could simply use a Math Node. Just define the mathematical function $Value$*2.
The node processes rows sequentially one at a time (top-down). The variable $Value$ will be replaced by the current value in each row. This logic is used in most Knime Nodes (except, for example, the external Python and R Integrations).

Hi,

For what you want you can use the Math Formula node to define a mathematical function to perform on your Value column. This will create a new column with the calculated values in the same table. You could then use the Column Splitter node to generate 2 separate tables.

Hope this helps/Evert

Yes, the “Math Formula” node, works just fine!

I think I need to “dwell” on the “set” nature of KNIME (like SQL statements), rather than “row by row” like VBA, C or Java.

Thanks to all!

1 Like

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