How to concatenate a string with a column value in rule engine

Is there a way to concatenate a string with the data available in a column

1 Like

Hi,

You can generate a string with the rule engine node, then use the column combiner node to combine the string with any column.

Is that what you want?

 

Nico

1 Like

Hi,

Or use the String Manipulation (join("blabla"," ",$Value$)

;-)

2 Likes

join() is my go to. noticed you left an extra parentheses on the sample join calculation.

(join(“blabla”," ",$Value$))

best,
t

Hello!
I tried the join() in the last line of the rule in KNIME Version 4.4:
TRUE => join("* ",$txtMyString$)
which results in following error:
“Expected a number, boolean, string, column, a table property or flow variable reference.”

$txtMyString$ is a string column

What’s wrong here?
Thanks
Matthias

You need a seperate node (e.g. string manipulation) after rule engine to do that.

1 Like

Hello @Daniel_Weikert !
Thanks for your response. The Point is:
In the rule engine, I aggregate different categories, but if I do not find a “overall” categorie, I would like to use the original categorie but want to add a flag. Thisway we can easily see if this is an aggregation or not. The rule engine ahould looks like this:
// aggregat UX-Testing, DB-Testing,…
$txtMyString$ LIKE “test” => “Testing
MISSING $txtMyString$ => “unknown”
TRUE => join("+ ", $txtMyString$)

… but the join as described in this thread does not work anymore.
Is there an easy way to replace the column with the new category, or do I have to add additional nodes where I must compare original category with the output of this new category. delete the old column and rename the new column?
Matthias

Hi @Matthias_W , as @Daniel_Weikert has mentioned, you have to do this in a separate node first.

join() has NEVER worked in the Rule Engine. The Rule Engine only accept these functions:
image

Any other operations/manipulations have to be done outside the Rule Engine.

Also, for $txtMyString$ LIKE "test" => "Testing" why are you using LIKE instead of = if you are not using wildcard? This should do: $txtMyString$ = "test" => "Testing"

So, for your sample code, you could do something like this in the Rule Engine:

$txtMyString$ = "test" => "Testing"
MISSING $txtMyString$ => "unknown"
TRUE => "PLUS"

And after that, you can do a join("+ ", $txtMyString$) via String Manipulation where the value is “PLUS”.

Alternatively, you can do all of this in a Column Expressions node where you apply both the rules and the join. Something like this would do:

if(isMissing(column("txtMyString"))) {
    "unknown";
} else if(column("txtMyString").equals("test")) {
    "Testing";
} else {
    join("+", column("txtMyString"))
}

This just 1 node transforms this Sample input:
image

Into this:
image

4 Likes

Hello @bruno29a
Thank you for your detailed answer.
I also have to apologize, since I have forgotten the * in my example. Actually I did mean “test” to match “UX test”, “DB test” etc.

The idea with the column expression is actually charming, since I only need one node. With the rule engine + string manipulation + column renaming + column deleting there are several steps necessary.

Thanks
Matthias

2 Likes