blog knime flow variables

A workflow can be defined as a collection of nodes. Depending on used nodes and its configurations, workflows can run either statically or dynamically.

So, what does statically and dynmaically running mean?

A workflow can be called as statically running if it generates same result at each run. On the contrary, a workflow generating different results by using different parameter at every run can be called as dynamically running. To make a workflow dynamic, we need flow variables.

How do flow variables appear in a workflow?

Generally, there are two different lines, black and red, connecting nodes in a workflow. The black one carries data like table, image, json, html etc. from node to another node while the red one carries variables.

All good, but how can we create them?

Answer of this question depends on needs. At this point, we just need to decide what we need and apply. Let’ s take a look at how can we use flow variables in a workflow.

There are generally two ways to create and use flow variables in a workflow.

  • Using Configuration Nodes For Flow Variable Creation

Sometimes we need to ask the user to enter a value -parameter- before running a workflow. This value may vary according to the needs of the user. So, we need to create a structure that capture these values entered by the user. Configuration (Double Configuration, Integer Configuration etc.) and Selection Nodes (Value Selection, Single Selection etc.) allows us to handle this problem.

Bu resim için metin sağlanmadı

We can see a sample sketchy workflow above. Thanks to Value Selection Node, we can capture the values entered by a user. As we see above, there are two values, Gender and M, entered by a user. These two values are called as variables. So far, we have captured user-defined variables. Now, let’ s feed our workflow with these variables. To do that, we need to connect corresponding nodes with a red line.

Now, let’ s take a closer look Row Filter dialog window. When we jump in the Flow Variables tab, we can see ColumnName and Pattern selections. As given below, we can define these selections to be fed by variables.

Bu resim için metin sağlanmadı

ColumnName is fed by user-defined-variable(column) variable i.e Gender, Pattern is fed by user-defined-variable variable i.e M.

If we take a look at the Row Filter output shown below, we can see the data filtered by M value in Gender column thanks to flow variables.

Bu resim için metin sağlanmadı

Thus, if the user enter another values, we can easily consider that the output data will be filtered with another user-defined values. By this way, each value entered by a user will be filtered automatically at the final table. This means that our workflow works dynamically.

If our goal is to filter a table by a specific value, one can think that this is not a only way to do that. Right, there are multiple ways to build a workflow in KNIME. In this case, we could have only used Row Filter node to filter a table by a specific value, but the flow will turn into a “static” structure. This means that each time we want to change the filtering criteria, we need to configure Row Filter node again.

  • Building a Loop

Another way to use flow variables is to build a loop. Sometimes, we don’ t have to pick a value from a user. However, we may need to use corresponding values iteratively.

Bu resim için metin sağlanmadı

As we can see the above sample, there is a recursively structure fed by flow variables at each iteration.

Consider that we have a transaction data, and we want to mark those data with a specific value like “1” or “0”.

Now, let’ s take a look our data shown below.

Bu resim için metin sağlanmadı

What we want to do here is to mark each transaction according to whether a transaction contains a certain value or not.

Let’ s show these markups in a new column with the help of Rule Engine node.

Bu resim için metin sağlanmadı

As we can see above, we have just one marked transaction so far. If we run the Loop End node, all transactions will be marked thanks to flow variable loop structure.

Bu resim için metin sağlanmadı

Thanks to the Table Row to Variable Loop Start Node, we have marked all transaction data with using flow variable in each iteration.

In this skecth, how variables are created and how they are used in general are mentioned. Sure, using flow variables depends on user needs. So, use of flow variables can not be limited. Here, only most common uses are mentioned.

Cheers

-Kerem