KNIME Flow Control Guide: KNIME AG, Zurich, Switzerland Version 4.3 (Last Updated On 2020-10-22)
KNIME Flow Control Guide: KNIME AG, Zurich, Switzerland Version 4.3 (Last Updated On 2020-10-22)
Flow variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Loop commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Breakpoint node . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
IF Switch node . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Error handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
KNIME Flow Control Guide
Introduction
Not all workflows have a static input and only one branch. Often, data are updated regularly,
and some settings can be different from time to time. In other cases a workflow might have
branches and a rule that determines which branch to follow.
In this guide, the tools available in KNIME Analytics Platform to control the flow in the needed
direction are introduced.
The nodes that come in hand here are shipped automatically with the KNIME Analytics
Platform and do not require the installation of any extension. You can find these nodes in the
node repositoy under the Workflow Control category as shown in Figure 1.
Flow variables
Flow variables are parameters with string, integer, double, arrays, or Path values. These
parameters can be used to avoid manually changing settings within the nodes of a workflow
when a new execution with different settings is required. Flow variables are available only for
the downstream nodes in the workflow.
The first two options are introduced in this section. The Widgets and Configuration nodes are
explained in more details in the Components Guide. However, an example that makes use of
this type of nodes in the context of creating a flow variable is available on KNIME Hub. An
example of the last option is the Rule Engine Variable node, which is introduced in the IF and
CASE Switches section.
The Table Row to Variable node, converts each column of the first row of a data table into a
flow variable. In the example in Figure 2, which is available on KNIME Hub, the Table Row to
Variable node is connected to Group By and Sorter node which respectively group the original
data by country, counting how many times an entry in the data corresponds to a specific
country and sorts the data accordingly, as shown in Figure 3.
The output of the Table Row to Variable node is shown in Figure 4. The column names in the
data table are now the names of the flow variables, while the values of the first row are the
corresponding values of the flow variables.
Another option to create a new flow variable is to export a node configuration. In this case
the flow variable acquires the same value used for the node configuration. The name for the
flow variable is defined in the node configuration dialog.
Some configuration options have a flow variable icon next to them, for example the string
pattern in the Row Filter node configuration dialog shown in Figure 5.
To export a node configuration that has a flow variable icon next to it, open the node
configuration dialog and follow these steps:
If there is no flow variable icon next to the setting to be exported, follow these steps:
Now, the Flow Variables tab in the output table view of the node, shows the exported flow
variable, as in Figure 8.
The flow variable ports are red circles above each node. Each node has flow variable ports,
but for most nodes they are hidden by default. You can make them visible by right clicking a
node and selecting Show Flow Variable Ports in the context menu as shown in Figure 9.
In the previous section, we explained how to create flow variables. Here, we show how to use
a previously created flow variable to configure a node.
In case you want to use a flow variable you need to first connect the node where the flow
variable is created to the following one. If they are not connected already via any other port,
use the flow variable ports. You need to create the connection only once, then the transferred
flow variables are available for all subsequent nodes in the workflow.
1. Open the configuration dialog of the node whose setting you want to overwrite via the
flow variable. The flow variable icon is not always present in the node configuration
dialog, but you can find it next to node configurations that are often overwritten by flow
variables.
a. If the chosen configuration setting has a flow variable icon next to it, click it and in
the Variable Settings dialog that opens select Use Variable. Then select the flow
variable from the drop-down menu, as shown in Figure 10.
b. If the flow variable icon is not present, go to the Flow Variables tab, navigate to
the chosen node configuration and select the flow variable from the drop-down
menu as shown in Figure 11.
When you overwrite a node configuration with a flow variable, a warning message appears in
the lower part of the node configuration dialog pointing out which node configuration is
overwritten, as shown in Figure 12.
Loops
Loops iterate over a certain part of the workflow. Each iteration, a repeated procedure, has
different input. What changes for each iteration can be a parameter value, dataset, subgroup
of the same dataset, single column, or single row as flow variables.
In the videos What is a Loop? and Counting Loop we explain the loop concept
and build a simple example loop.
A loop in KNIME begins with a Loop Start node and ends with a Loop End node. The
operations that are performed for each iteration are executed in the loop body. Generally, the
Loop Start node is responsible for increasing the iteration counter and for sending the data to
the loop body, which is then responsible for executing sub-workflow steps. After those are
performed the Loop End node checks if the end condition is fulfilled, and if this is not the
case the Loop Start node increases the counter and performs the loop body operations
again. When the end condition is fulfilled, the Loop End node collects the data from the
different iterations and the next step in the workflow is performed.
The loop in Figure 13, which is available on KNIME Hub, is an example where the Chunk Loop
Start node is used to iterate over a table, which contains ten rows filled with the letter A,
created with the Table Creator node.
Table Creator Chunk Loop Start Value Counter Loop End
The Chunk Loop Start node takes three rows of the input table and sends a chunk of the data
to the loop body, which is made of a Value Counter node. Finally, a Loop End node collects
the results of each loop iteration and ends the loop when the condition of reaching the last
row of the input data is fulfilled.
KNIME Analytics Platform provides different loop start and loop end nodes for different types
of loops. The loop start and loop end nodes are collected into Table 1 and Table 2. You will
find these nodes in the node repository by navigating to Workflow Control → Loop Support.
Table Row To Variable Loop Start Converts every row in a table into
row variables and iterates over
them
Recursive Loop Start (2 Ports) Iterates over the two output data
tables from the Recursive Loop
End (2 ports) node
Loop commands
While executing a loop, you can follow the execution monitoring a selected node output using
the node monitor.
• Complete execution: Right click the Loop End node and choose Execute from the
context menu. Now a yellow loop sign is shown at the Loop End node while the loop
steps are executed. As soon as it turns to green the loop is completely and successfully
executed. To reset the loop you can reset any of the nodes that belong to the loop sub-
workflow, by right clicking a node and choosing Reset from the context menu.
• Step-wise execution: Right click the Loop End node and choose Step Loop Execution
from the context menu, to execute one iteration of the loop. At any time you can
execute the remaining steps by choosing Resume Loop Execution from the context
menu of the Loop End node. You can also pause the step-wise execution or cancel it,
choosing Pause Execution or Cancel from the context menu of the Loop End node. In
both cases this affects only the Loop End node, while the antecedent nodes will still be
in the executed state.
The videos Loop End Nodes and Loop Commands explain loop end nodes in
more detail and show guided loop execution options.
An example for Table Row to Variable Loop Start is shown in Figure 14, and is also available
on KNIME Hub.
Table Row To
Table Creator Variable Loop Start
Random
2D Points
Figure 14. An example of loop with Table Row to Variable Loop Start node
Similarly to the Table Row to Variable node, the Table Row to Variable Loop Start node
transforms the row of a table to a set of variables that have as name the column name and
as value the corresponding value in the current row. It loops over each row of the input table
and exposes the flow variables obtained to the loop body. In the example in Figure 14, one of
the flow variables obtained is used to overwrite the column value parameter setting of the
Constant Value Column node, which appends a cell containing the current value to the
current table.
Breakpoint node
In the node repository, under Workflow Control → Loop Support, Breakpoint node is also
available. You can use it to halt execution when certain conditions are met. Figure 15 and
Figure 16 show the use of this node to impair the execution of the loop when the input flow
variable corresponding to the value of the customer segment is equal to three. You can also
configure the Breakpoint node to halt execution when it receives as input an empty table, and
active or inactive branch. You can also set a Custom message to be shown if the Breakpoint
node condition is met. This workflow is also available on KNIME Hub.
Table Creator Counting Loop Start Value Counter Breakpoint Loop End
paused
IF Switch node
The IF Switch node creates two branches in the workflow which can be alternatively activated
or disactivated. This means, the nodes in the active branch or branches are executed and the
nodes in the inactive one are not. In the node configuration dialog you can define the active
branch either manually, or it can be dynamically controlled by a condition, through a flow
variable.
The example workflow in Figure 18, also available on KNIME Hub, loops over an IF Switch to
read in data row by row, to categorize the customers based on their call activity. When the
loop is finished, the rows are concatenated back into the same table.
Constant
String Input Value Column
IF Switch End IF
Bottom port selected Replace input column with
constant value 'bottom'
Creates a
single column. In each row
only the letter 'A' entered.
In the workflow in Figure 18, the IF Switch node has both data and flow variable input. The
flow variable, created with the String Input node, defines the active branch. The data are then
handled in the active branch.
First, you need to create a suitable flow variable. Since you need to use it to overwrite the
Select active port option of the IF Switch node, you have to assign to it a string value equal to
either both, bottom or top.
In the example shown in Figure 18 this flow variable is created using a String Input node
which allows to manually set the output flow variable to one of the suitable string values.
Constant
Value Column
Transforms Sets a condition
the current row where some value
into flow variables activates a port
'A' -> top End IF Loop End
Table Creator Chunk Loop Start 'B' ->bottom IF Switch Replace input column with
constant value 'top'
The Rule Engine Variable node configuration dialog is shown in Figure 21. Here the
antecedents are defined using the flow variables and functions available while the
consequent of a true condition is assigned with the => sign. The default outcome, i.e. the
value assigned to all cases for which none of the rules is true, is defined using the syntax
TRUE => "default outcome".
Once the execution has finished, the tables resulting from the branches can be concatenated
by using an End IF node or CASE Switch Data (End) node.
An example, similar to the one of IF Switch Data node, is shown in Figure 22 and available on
KNIME Hub.
Note that when using the CASE Switch, the possible values for the active output
port are 0 for the top, 1 for the middle, and 2 for the bottom output port. That
said, the functionality is similar, but the flow variable values are different.
Error handling
Different type of errors, such as a failing connection to a remote service, the invocation of a
not accessible database, and so on, can occur when executing a workflow. To handle them
you can use the Try-Catch enclosures. The Try part executes some node(s). If the execution
fails, the Catch branch with error handling is activated. Otherwise the Default branch is
executed. At the end of the Try-Catch enclosure, the results from either the successful or
failed execution are collected. An example of a Try-Catch enclosure is shown in Figure 23,
which is available on KNIME Hub.
Table Creator Counting Loop Start Try (Data Ports) Breakpoint Catch Errors Loop End
(Data Ports)
Creates a Start Counting Start the try block Fails in Iteration 15 Collects the results
single column. In each row Catches errors of each loop iteration, without
only the letter 'A' entered. 'A' for iteration 15.
Active Branch
Inverter
Empty Table Creator
Node 11
Creates empty input
if break-point triggers a fail
In the workflow in Figure 23, the Try (Data Ports) node begins the enclosure, followed by the
Breakpoint node. The Breakpoint node is set to fail at the fifteenth iteration. Here, if execution
of the Try part fails the Catch branch is executed.
The Active Branch Converter node begins the Catch branch for error handling. This node
makes an inactive branch active and active branch inactive:
The Catch Errors (Data Ports) node closes the Try-Catch enclosure:
• If execution is successful, the output of the node is the output from the Default branch.
Therefore, the Default branch must be connected to the top input port of the Catch
Errors (Data Ports) node.
• If execution fails, the output of the enclosure comes from the Catch branch, which must
be connected to the bottom input port of the Catch Errors (Data Ports) node. The
reasons for the failure are then reported in the flow variable output of the Catch Errors
(Data Ports) node.
Besides data tables, the Try part can also be started with a flow variable, using the Try
(Variable Ports) node instead.
One of the following four alternatives is available to end the Try-Catch loop:
You will find the nodes for a Try-Catch enclosure in the node repository by navigating to
Workflow Control → Error Handling.
The KNIME® trademark and logo and OPEN FOR INNOVATION® trademark are used by KNIME AG under license
from KNIME GmbH, and are registered in the United States. KNIME® is also registered in Germany.