Referencing column names in Rule Engine rules when column looping

Basic requirement:
I need to replace the word NULL in a collection of columns with a KNIME missing value (?).

Easy solution:
Use rule engine to test whether the cell value is NOT the keyword (NULL) and return the value - if the value is NULL then no value is returned. Repeat rule engine nodes for every column (and add/remove nodes every time the table structure change - Aaaaaargh).

Desired solution:
Use Column List Loop Start and Loop End nodes to wrap a Rule Engine. Within the rule engine create a rule with the variable name to select column and return value from column if vale is not NULL (the same as the easy solution, but replacing the column name with the variable name for the column) i.e.
NOT $${ScurrentColumnName}$$ = “NULL” => $${ScurrentColumnName}$$

I have created a workflow demonstrating both approaches on KNIME Hub

Problem:
The desired solution with the loop and variable names in Rule Engine doesn’t work. Instead of recognising the variable as a reference to a column, rule engine treats the $${ScurrentColumnName}$$ as a string variable and returns the string value of the column name.

Is this the correct behaviour for the column reference, and if so, how can we include references to columns within rule definitions?

Hi @DiaAzul -

Maybe this workaround using the Column Expressions node to replace the Rule Engine will help?

2021-03-17 12_23_04-Collected results - 4_1126 - Loop End (Column Append) (End loop)

4 Likes

Thank’s, long time since I used Column Expressions…there are too many ways to do things in KNIME.

Would be nice to have the Column(…) in Rule Engine, given that the same format turns up in so many nodes (e.g. Row Filter, etc…).

1 Like

Hello @DiaAzul,

this sounds like a job for String Manipulation (Multi Column) node with following expression:
toNull( replace( $$CURRENTCOLUMN$$, "NULL" , "") )

Also you can unpivot your data, apply logic and pivot it back (see example here).

For loop with Rule Engine use Column Rename (Regex) node before and after it (example here).

Talking about different ways solving issues in KNIME…

Br,
Ivan

2 Likes

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