Error when use columns with () in String Manipulation

I am trying to join some columns here, but I think the () in column name cause this error. How can I deal with column names with ()?

Even when I remove the () with column rename, I still cannot add those column into the JoinSep function.

Hi @cuimaple ,

The java error message is reporting that you are trying to include Long columns on the concatenation, and the joinSep function is designed to concatenate strings.

I suspect it is this rather than the parentheses in the column name causing the problem.

For columns that are not strings, you should try wrapping them with the string( ) function,

Eg

joinSep("|", $col1$, $col2$, $col3$, string($long-colA$), string($long-colB$))

(replace with your actual column names. I’m writing this on my phone and as your column names are only in screen shots, I can’t easily copy your code)

The internal message is being reported back by the java compiler which is unfortunately not very user friendly in this regard.

Yes, you are right!
But I also encounter situation that when I deal with string containing special characters like /, ", , then string manipulation will pop up warning message. Do you know how to deal with these special characters?

hi @cuimaple ,

I can’t think of a reason why you’d encounter problems trying to concatenate the / provided that you enclose it in double quotes

e.g.
joinSep("/",$column1$,$column2$)

However, the \ character is likely to cause issues because it is what is known as an “escape” character, which means it give (or remove!) “special meaning” from the character that follows it.

If you wish to concatenate a \ you need to use two \\ as the first one means "remove the special meaning of the following \

e.g.
joinSep("\\",$column1$,$column2$)

or
join($column1$,"\\",$column2$)

If you want to concatenate double quotes ito your string, you need to include the \ character prior to the double quote i.e. \" , which removes the normal “special meaning” of double-quote as a string terminator.

e.g
if we had a table

column1 column2
abc def

join($column1$,"\\",$column2$)

would return
abc\def

and

join("\"",$column1$,"\\",$column2$,"\"")

would return (including the double quotes):
"abc\def"

whereas the / does not have any special meaning and so

join($column1$,"/",$column2$)

would return
abc/def

If you had a column names such as column$1 and column\2 (which I wouldn’t recommend, but I guess it could happen), you would need to include additional \ in the column name ahead of the $ and the \, because in referring to column names, $ has a special meaning (it tells the node that between the two $ signs it will find the the column name), and \ continues to have special meaning as the escape character

e.g if I had this table:

column$1 column\2 column"3" column,4
abc def ghi jkl

I would have to modify my code to “escape” all the characters in the column names that are likely to cause problems with syntax, so that instead of

joinSep("|",$column$1$,$column\2$,$column"3"$,$column,4$)
which would cause this error:

I would have to write it so that every special character in column names is preceded by \ …

joinSep("|",$column\$1$,$column\\2$,$column\"3\"$,$column\,4$)

If you are still having problems or have questions, please give a further example of your code, and the error you see.


EDIT:
I have just been experimenting with / in the column name, since you mentioned this causing problems. It appears that if you have a column name such as column/2, you can reference this as either

$column/2$
image

or

$column\/2$
image

and KNIME will allow either of the above, although the editor syntax colouring changes, as it gets a little confused!


3 Likes

very helpful! thanks!

1 Like

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