Icon

Switch - Examples of how to use Case When

Three ways to handle combination of Flow variables from Python and If switches

In one Python environment a Flow Variable for the usage in KNIME will be filled and the results will be used for two If switches.

if($${Ivar_py_value_switch}$$ >0) {return "bottom";}
else {return "top";}

URL: forum entry (27913) https://forum.knime.com/t/to-control-workflow-stream-using-if-switch-using-flow-variable-from-a-python-snippet/27913/2?u=mlauber71
URL: Meta Collection about KNIME and Python https://kni.me/w/AvjrddXKOIoZYLV3
URL: Vernalis KNIME Nodes https://hub.knime.com/vernalis/extensions/com.vernalis.knime.feature/latest
URL: DB SQLite - switch datase source based on a case when selection https://forum.knime.com/t/db-query-case-switch/63990/7?u=mlauber71
URL: META: A meta collection about Loops, Switches, Paths and Flow Variables in KNIME (and some ZIP files) https://hub.knime.com/-/spaces/-/latest/~CET0X2z2VY9oKlYN/

decide if
TOP or
BOTTOM

import knime.scripting.io as knio

import sys
import pandas as pd
# data processing, CSV file I/O (e.g. pd.read_csv)

input_table = knio.input_tables[0].to_pandas()

# this setting will be used as a flow variable in KNIME

# knio.flow_variables['var_py_value_switch'] = 0
knio.flow_variables['var_py_value_switch'] = 1

var_py_version = sys.version
var_py_version_pandas = pd.__version__

knio.flow_variables['var_py_version'] = sys.version
knio.flow_variables['var_py_version_pandas'] = pd.__version__

data = {'sys_version': [var_py_version],
'pandas_version': [var_py_version_pandas]
}

knio.output_tables[0] = knio.Table.from_pandas(input_table.copy())

# pass column names in the columns parameter
knio.output_tables[1] = knio.Table.from_pandas(pd.DataFrame(data))
Three ways to handle combination of Flow variables from Python and If switches

https://forum.knime.com/t/to-control-workflow-stream-using-if-switch-using-flow-variable-from-a-python-snippet/27913/2?u=mlauber71

In one Python environment a Flow Variable for the usage in KNIME will be filled and the results will be used for two If switches.

Blog: KNIME - Cases, Switches and Catching Errors

https://medium.com/p/5ab748cbeaa3

dummydata
Data Generator
v_result_switchSTART
IF Switch
result Python
End IF
v_result_switch"top"or "bottom"derived from Pythonvar_py_value_switch
Java Edit Variable (simple)
v_result_case_portset the active port via Integer Flow Variable
CASE Switch Start
bottom_result.xlsx
Excel Writer
CASE Switch End
v_result_case_portset the active port via Integer Flow Variable
CASE Switch Start
v_result_switchv_result_case_port
Variable Expression
bottom Python
Python Script
END
CASE Switch End
top Python
Python Script
CASE Switch Start
some Python script
Python Script
v_result_case_portwhich port should be activederived from Pythonvar_py_value_switchif($${Ivar_py_value_switch}$$ >0) {return 1;}else {return 0;}
Java Edit Variable (simple)
top Python
Python Script
bottom Python
Python Script
top Python
Python Script
top_result.xlsx
Excel Writer
result
CASE Switch End
bottom Python
Python Script
top Python
Python Script
bottom Python
Python Script

Nodes

Extensions

Links