Column expressions adds a "(#1)" to each column name

I have two expressions in a Column Expression node. I have a simple string manipulation expression to strip each column of whitespace, and a rule expression which removes empty strings. I’m very new to Knime but i think these work ok except the rule expression adds “(#1)” to every column name. The names go into the column expressions node as (e.g.) “Product_code_1” and come out as “Product_code_1 (#1)”.

Clearly I’m doing something wrong but i don’t know what.

Below is a screenshot of the nodes in sequence, the regex nodes change the column names all to ANONYMOUS_COLUMN and then changes it back with a flow variable. I tried to make the workflow without renaming the columns and adding the flow variable of the currentColumnName to the output flow variable in the column expression node, but this worked out even worse as each column was duplicated 3 time. I saw someone using the renaming technique in an example in order to make the Output Column on the expression dynamic (instead of using flow variable).

The rule expression is:

if (column(“ANONYMOUS_COLUMN”) != “”) {
column(“ANONYMOUS_COLUMN”)
}

Hi there @ThomasJ,

welcome to KNIME Community!

How about using String Manipulation (Multi Column) node if you are performing same manipulation over multiple columns?

Have couple of ideas what could be wrong in your current design but it would be best if you share workflow to avoid unnecessary guessing if you are interested to find that out :wink: See here how to do that:

Br,
Ivan

I really like the Column expression node as it lets us build some fairly complex logic without having to go to another node.

2 Feature requests:

  • add a function to let you use regex to parse out parts of a string as a capture group
  • allow you to use new output columns created in expressions above it to be used in the current expression… I realize the workaround is to use a second node after the column is created with the new column… this one is definitely less important

Hi @DemandEngineer,

That is a good suggestion, you can already do this with the Regex Split node though, even if that is a bit less handy than column expressions.

best,
Gabriel

Thanks for the suggestion, @gab1one . I was mainly asking for that feature so that I could have access to the regex in the same node’s if else logic. I wanted to avoid doing the regex first to create a new column of data just for the logic and then filtering out the column after.

Yes that makes a lot of sense, I will add this to the list of possible improvements of that node. Just wanted to let you know that the regex node exists so you can do what you, even if it is not as convenient as it should be.

best,
Gabriel

1 Like