Expression Node - I simply do not understand its inner workings

Dear KNIMErs,

I really have difficulties in understanding how the Expression nodes work. Especially now since it has officially replaced a lot of the “old nodes” (like Rule Engine, String Manipulation etc)

Let me give you an example.

I have a column holding date differences as an integer.

I want to categorize this in 3 different categories:
0 - 30 days
31 - 60 days

60 days

In the “old world” I would have used a Rule Engine, that was easy to understand and even kind of visual (with its => operator)

Diff >= 0 AND Diff <= 30 => “cat 1”
Diff >= 31 AND DIFF <= 60 => “cat 2”
TRUE => “cat 3”

Easy peasy.

Now in Expressions, K-AI suggests switch or If which are both explained in a kind of confusing way.

I want to use the most up to date nodes because I think they offer some great opportunities, but right now for me this feels like a big step backwards, tbh.

ps: the KNIME forum software does not seem to accept line breaks anymore…

2 Likes

Hi @kowisoft,

you are not alone. I too struggle to put it to proper use. Maybe this PDF helps you?

The new Expression Nodes purpose is to:

Enables row-by-row data manipulation to add or replace columns.

So it would be like shooting with canon balls on flies. Why not use a simple biner with evenly spaced bins like so?

Here is the (possible) solution:

Best
Mike

4 Likes

you are probably right, it actually IS shooting with canons at flies.

The thing is I tried to use the Expressions node quite a few times as a replacement for some of the older nodes (as per the KNIME learning curriculum) and have found it more complicated (personal opinion here!)

I definitely want to use it because it seems to offer some great opportunities, however, I was not able to realize them (that probably will come)…

Thanks for the guide though.

1 Like

You are not alone. During the community hacking days some feedback was given about the new expression node. Personally, I feel it attempts to become a “Eierlegende Wollmilchsau” and presents a step away from Knimes core concept of Codeless. I alse do not see what exact problem this nodes solves in the first place except polishing the UI. Anyways, different topic.

Coming back to your original challenge, the expression node would be useful in case you want to determine if the days diff between the current and the next row falls into a certain bucket.

Shall I hack somethigng together for you?

3 Likes

thanks a lot, Martin. Not necessary to do something. Because I have cut my ego a bit and instead of “wanting to use the Expressions Node” I simply used the good old Rule Engine. Why go for something more complex, when this is not necessary…?

2 Likes

Hi @kowisoft ,

the new syntax is like this:

if(0 <= $Diff and $Diff <= 30, “cat 1”,
   31 <= $Diff and $Diff <= 60, “cat 2”,
   “cat 3”)

We also thought about a more visual replacement for the Rule Engine that would split up the big input field and make the rules more visual. However, we parked that idea for now, since the “if” function with one rule per row – as in the example – is very close to what the Rule Engine looks like. I agree though, that the old “=>” had a more visual appeal than the comma in the new syntax.

Just in case you want to reconsider using the Expression node,
nan

7 Likes

let me chime in here - I agree that Expressions Node is not perfect, but honestly I enjoy the opportunity to solve different kinds of rather simple problems with one node - if I have access I “cheat” and ask K-AI to do something for me and that is the appeal.

That said I feel like I am starting to get used to the new syntax and despite some inconsistencies (some functions reference columns as “column1”, others require the $ signs etc…) I start to like it :slight_smile:

2 Likes

@nan if, then, else operations are the most common used and I also was initially struggling how the new node does handle that. Since I also was not able to find a hint in the documentation.

I took some time to replicate the rules from a Rule Engine in the Expression Node to better display the discomfort the new Expression Node causes:

Rule Engine


1.750 Characters

Expression Node


1.958 Characters (+11 %)

  • Rule Engine offers much better syntax highlighting
  • Rule Engine clearly separated from Result using => syntax
  • Rule Engine logic operators AND, OR` better recognizable
  • Typography provides a better contrast (font weight regular vs. light, background color light blue … why???)
  • No excessive nesting (likely bcs. of missing elseif in Expression Node Syntax), making logic easier to follow
  • Colors help differentiate rules and conditions
  • Variable types better distinguishable in Rule Engine

Error handling
Rule Engine


Clear visibility

Expression Node


Poor visibility

Variables
Rule Engine
image

Expression Node

Suggestions

  1. Replace the light blue by a regular white background
  2. Switch to regular or medium font size
  3. Improve syntax highlighting (brackets, variables vs. column references, operators)
  4. Code Consistency / Flexibility: Comparisons like == are allows but && instead of and ain’t. if-Clause is supported but not elseif
  5. Add Auto-Indentation and option to press CTRL+A > Shift+Tab

Any maybe more but I’d like to invite others to provide their “two cents” too :wink: Enjoy your weekend …

Best
Mike

12 Likes

Big +1 for Mike’s suggestions.

It feels especially alienating for me because the “old” column and variable expressions node were such good additions, and the new node feels very lackluster in comparison. Additionally, it introduces yet another new “programming” syntax to learn in Knime.

My suggestions:

  • Fewer comments at the start of an expression. Especially in the embedded view, it is really hard to see the first empty line to write on.
  • Make expressions even more distinguishable from one another, perhaps by graying out the inactive ones.
  • Collapsing the expressions would help with clarity as well. Take inspiration from the old column expressions node, where you first had to click on the expression to see the code.
  • Add more information in the header of an expression, such as indicating which row is replaced or appended. Another option is to allow users to give it a custom name.

And lastly a more personal one: Please change the syntax of the If statements! I understand the intent to have it like a Excel formula but like in Excel it is just hard to read and feels really unnatural with a programming background.

Best regards,
David

4 Likes

given the inputs provided I have moved this to Feedback & Ideas :slight_smile:

3 Likes

Could I add a +1 to @mwiegand’s earlier comments that the font colour and weight provide poor visibility compared with the older nodes .

For me the new Expression nodes (and the new Python scripting nodes) are incredibly tiring on the eyes for prolonged use as they are difficult to read. (I feel like I’m reading it through a light fog)

Maybe when I was younger, with better eyes, I’d have been ok, but not these days!

All modern IDEs provide the ability to set the colour scheme according to user preference, and need, but with no ability to change the colours and font weight, the chosen scheme should at least be practical rather than what appears to be “form over function” and simply dim-and-faint-for-the-sake-of-it.

I really hope such comments are taken on board because being able to read the screen easily shouldn’t be a “nice to have”.

7 Likes

Knowing the MUI (Modern UI) is HTML based, I was hoping to find the CSS but couldn’t spot it so far. Maybe I wasn’t looking deep enough …

3 Likes

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