Skip to content

Expression language reference ​

Expression nodes ​

Three nodes use the Knime Expression Language:

NodeWhat it does
ExpressionAdds or replaces columns, evaluated row by row
Expression Row FilterRemoves rows where the expression evaluates to FALSE
Variable ExpressionCreates or modifies flow variables

Each node's configuration dialog has three panels: input columns and variables on the left, an expression editor in the center, and a function catalog with descriptions and examples on the right. All three nodes support K-AI for AI-assisted expression generation — see Generate code in expression or script node.

The Expression and Variable Expression nodes support multiple expressions evaluated in sequence, top to bottom. The output value of an expression can be used in the following expressions. Each expression has its own output configuration — a new column name or an existing column to replace.

Language reference ​

Value types ​

TypeDescriptionExample literals
BOOLEANTrue or falseTRUE, FALSE
INTEGERWhole numbers (64-bit signed)42, 1_000_000
FLOATDecimal numbers (64-bit IEEE 754)3.14, 1.5e-3
STRINGText (Unicode)"hello", 'world'
LOCAL_DATEDate without time— (no literal; use functions)
LOCAL_TIMETime without date—
LOCAL_DATE_TIMEDate and time combined—
ZONED_DATE_TIMEDate, time, and time zone—
DATE_DURATIONAn interval between dates— (no literal; use functions)
TIME_DURATIONAn interval between times—
MISSINGAbsent valueMISSING

Any type can be optional — written as TYPE | MISSING — meaning the column or variable may contain missing values.

BOOLEAN ​

The value type BOOLEAN is used for logical values, that are either true or false. If handling optional values, i.e., type BOOLEAN | MISSING, Kleene's three-valued logic will be applied.

For more details, see the section on comparison.

BOOLEAN literals are either TRUE or FALSE.

BOOLEAN in the expression language maps to the [Boolean, BooleanType] column type.

INTEGER ​

The value type INTEGER is used for whole numbers. INTEGER literals are written in decimal form as digits between 0 and 9 with optional _ for visual separation. The first digit cannot be 0 unless the number is 0 itself.

The values are represented as 64-bit signed two's-complement integers resulting in a value range from -9_223_372_036_854_775_808 to 9_223_372_036_854_775_807 (inclusive).

Column types [Number (Integer), IntType] and [Number (Long Integer), LongType]¹ are mapped to INTEGER in the expression language without loss of precision. The output of an expression that returns the INTEGER expression type will be of the column type Number (Long Integer). For flow variables, there is a dropdown menu in the output section of each expression editor where you can select the desired type, i.e., IntType or LongType.

FLOAT ​

The value type FLOAT is used for numbers with fractional parts.

A FLOAT number is written with a decimal point. The decimal point can be at any position in the number, even at the beginning or end, like 0.123 or .123 or 123. You can use underscores _ to separate digits to make large numbers easier to read, like 1_000.567_890 is the same as 1000.567890

You can write FLOAT numbers using scientific notation, which is useful for very large or very small numbers. In scientific notation, e or E is used to denote "times ten to the power of". You can also use a plus + or minus - sign after e or E to indicate positive or negative exponents, so that 1.23e4 or 1.23E+4 means 1.23 * 10^(+4) or 12300.

The syntax for FLOAT literals is similar to the syntax used in Python. The values are represented as double-precision floating point numbers (64bit IEEE 754). This results in a value range from 4.9E-324 to 1.8E+308 (inclusive) and a precision of about 15 decimal digits.

FLOAT in the expression language maps to the [Number (Float), DoubleType]¹ column type and has the same precision.

For operations applied to INTEGER and FLOAT, such as 5 * 3.14, the INTEGER value is converted to FLOAT automatically. This may cause a loss of precision for very large numbers.

STRING ​

The value type STRING is used for sequences of Unicode characters (text). The values are represented as a sequence of characters enclosed in double quotes "text" or single quotes 'text'.

New lines in strings are permitted, so the string can span multiple lines without using a special character.

"multi-line
string"
->
multi-line
string
Escape sequences ​

The backslash \ can be used for escape sequences. A backslash that does not match one of the following escape sequences is an invalid syntax.

Escape sequenceDescriptionExample
\<newline>Backslash followed by a new line is ignored in the input text."xyz \<newline>abc" → xyz abc
\\Escapes the backslash itself."\\something\\" → \something\
\'Escapes single quotes."\'quoted text\'" → 'quoted text'
\"Escapes double quotes."\"quoted text\"" → "quoted text"
\bASCII backspace moves the cursor backwards over the previous character."Hello, W\bWorld!" → Hello, World!
\rASCII carriage return moves the cursor to the beginning of the line."Hello,\rWorld!" → World!
\nASCII linefeed moves the cursor to the next line. On Unix-like systems, this is the newline character; on Windows, it is used with \r."Hello,\nWorld!" →
Hello,
World!
\tASCII horizontal tab moves the cursor to the next tab stop."Hello,\tWorld!" → Hello, World!
\uxxxxUnicode character escape; xxxx is a 16-bit hex value."\u0041" → A
"\u00E4" → ä
"\u2328" → ⌨

Escape sequences are replaced from left to right and the resulting character of an escape sequence cannot be part of another escape sequence.

Date-time types ​

The Knime Expression Language supports several different date and time types, collectively referred to as 'date-time types'.

The supported types are:

  • LOCAL_DATE, for dates without time information,
  • LOCAL_TIME, for times without date information and without time zone information,
  • LOCAL_DATE_TIME, for combined dates and times without time zone information,
  • ZONED_DATE_TIME, for combined dates and times with time zone information.

These types cannot be written as literals, but columns of the corresponding types can be used in the expression language, and various functions and operations are available that can create and manipulate them.

Duration types ​

The Knime Expression Language supports duration types. These represent amounts of time, like the difference between two dates or two times. The supported types are:

  • DATE_DURATION, for intervals between dates, which map to the Knime Analytics Platform's date-based duration,

  • TIME_DURATION, for intervals between times, which map to the Knime Analytics Platform's time-based duration.

Much like the date and time types, these cannot be written as literals, but columns of the corresponding types can be used in the expression language, and various functions and operations are available that can create and manipulate them.

MISSING ​

The value type MISSING is used for missing values. It is used to represent the absence of a value in a cell or row, either because the value was missing in the input data or because the value could not be computed.

The literal for a missing value is MISSING. It is case-sensitive and must be written in uppercase. The literal, i.e., the explicit use of MISSING in an expression is not interchangeable with the optional type. So, while some_function($["column with only MISSING values"]) is valid, some_function(MISSING) is not and will result in a syntax error. For an expression that just returns MISSING without any further operation also a syntax error will be raised as the type of the expression would not be defined.

Access input data ​

Read a column value in the current row:

$["Column Name"]       # any column name, including spaces
$column_name           # shorthand for names with only letters, numbers, underscores

Column names are case-sensitive.

Special row identifiers:

$[ROW_NUMBER]    # current row number, starting at 1
$[ROW_INDEX]     # current row index, starting at 0
$[ROW_ID]        # RowID string, e.g. "Row42"

The row number, row index, and row ID are not column names and therefore are not enclosed in quotes. Shorthand syntax is not allowed for these special identifiers.

Read a value from a different row:

$["column_name", -1]   # value from the previous row
$["column_name", 1]    # value from the next row
$["column_name", -2]   # value from two rows before

The offset must be a static number — it can't be an expression itself.

If the expression replaces the column it reads from, the offset always sees that column's original values for the whole table — not values already recalculated earlier in the same evaluation pass.

Accessing a row that doesn't exist returns MISSING.

Read a flow variable:

$$["flow var name"]    # any variable name
$$flow_var_name        # shorthand

Flow variable names are case-sensitive.

Arithmetic operators ​

OperatorDescription
+Addition (also string concatenation)
-Subtraction or negation
*Multiplication
/Division (always returns FLOAT)
//Floor division (returns INTEGER)
**Exponentiation
%Remainder

If both operands are of the same type, the result is of the same type if not specified otherwise for the specific operator. If one or both of the operand types is optional, the result is optional. If the operands are of type INTEGER and FLOAT (order irrelevant), the INTEGER value is promoted to FLOAT.

Division by zero ​

Dividing by zero with /, //, or % doesn't raise an error — it returns a defined result and a runtime warning.

OperatorConditionResult
/The first operand is 0NaN — e.g. 0. / 0
/Both operands have the same signINFINITY — e.g. 1. / 0
/The operands have different signs-INFINITY — e.g. -1. / 0
//Any0 — floor division always returns an INTEGER
%The first operand is FLOATNaN
%Both operands are INTEGER0

Arithmetic operators for date-time and interval types ​

NameDescription
Addition (+)Can be applied to:
  • A date-time with date information and a DATE_DURATION, to yield a new date-time of the same type with the duration added to the date (the time information usually remains unchanged, except in cases such as daylight saving time). The date-time must be the first operand.
  • A date-time with time information and a TIME_DURATION, to yield a new date-time of the same type with the duration added to the time (this may alter the date information). The date-time must be the first operand.
  • A DATE_DURATION with another DATE_DURATION, or a TIME_DURATION with another TIME_DURATION, to obtain an interval equal to the sum of the two durations.
Subtraction (-)Can be applied to:
  • A date-time with date information minus a DATE_DURATION, to yield a new date-time of the same type with the duration subtracted from the date (which will usually leave the time information unchanged, except in cases where this is not possible due to e.g. daylight saving times). The date-time must be the first operand.
  • A date-time with time information minus a TIME_DURATION, to yield a new date-time of the same type with the duration subtracted from the time (which may alter the date information). The date-time must be the first operand.
  • A DATE_DURATION with a DATE_DURATION or a TIME_DURATION with a TIME_DURATION to obtain an interval equal to the difference of the two operands.
  • Two LOCAL_DATE values, to obtain a DATE_DURATION equal to the difference of the two dates.
  • Any two LOCAL_TIME, any two LOCAL_DATE_TIME, or any two ZONED_DATE_TIME values, to obtain a TIME_DURATION equal to the difference of the two date-time values.
Multiplication (*)Can be applied to:
  • A TIME_DURATION with an INTEGER to obtain a TIME_DURATION value that has the same length as the original duration multiplied by the number.
  • A DATE_DURATION with an INTEGER to obtain a DATE_DURATION value that has the same length as the original duration multiplied by the number.

Comparison operators ​

Comparison operators are used to compare two numeric values (FLOAT and INTEGER) and yield a BOOLEAN result. The comparison operators are also applicable to date-time and interval types, with the exception of the DATE_DURATION type, which does not support any kind of ordering.

OperatorMeaning
<, <=, >, >=Ordering (numeric, date-time, duration)
= or ==Equality
!= or <>Inequality

Comparing any value to MISSING returns FALSE, except <= and >= where MISSING <= MISSING and MISSING >= MISSING are TRUE. Equality operators work on all types as long as both operands are of the same type or MISSING, with the exceptions that INTEGER and FLOAT can be checked for equality with one another, and ZONED_DATE_TIMES cannot be checked for equality at all.

When considering date-time and duration types, the comparison operators work as follows:

  • < and > compare the date-time values in chronological order. A later date-time is considered greater than an earlier date-time. A longer duration is considered greater than a shorter duration. Note that DATE_DURATION is not ordered.

  • <= and >= as with > and <, but including equality.

  • = and != compare the date-time values for equality. Two date-time or two duration values are considered equal if they have the same type, and respectively represent the same point in time or the same duration. Note that these operators are not applicable to ZONED_DATE_TIME values.

Logical operators ​

OperatorDescription
andTRUE if both operands are TRUE
orTRUE if at least one operand is TRUE
notInverts a boolean

Knime uses Kleene's three-valued logic when MISSING values are involved — for example, TRUE or MISSING evaluates to TRUE because the result is true regardless of the unknown value.

Missing coalescing operator ​

Use ?? to provide a fallback when a value is MISSING:

$["column"] ?? "default"     # returns "default" if the column value is missing

Both operands must have the same type and the result is of the same type. If both operands are MISSING values, the result is MISSING. Even though it will rarely be useful, you can pass MISSING as one of the arguments to ??. However, MISSING ?? MISSING is treated as syntax error.

String concatenation ​

Use + to concatenate strings. If one operand is a number, it is converted to a string automatically:

"Hello" + " " + "World"    # → "Hello World"
"Value: " + 42             # → "Value: 42"
"Hello" + $["column with missing value"]    -> "HelloMISSING"
"Hello" + MISSING                           -> Syntax error

Comments ​

Use # to add comments — the rest of the line is ignored:

# This entire line is a comment
$price * 1.2   # apply 20% markup

Functions ​

There are two types of functions that are usable in an expression: (1) Row-wise functions that apply row-wise to generate a new value from one or multiple values of each input row and (2) Aggregation functions that apply to a whole column to generate a single value that can be used for each evaluated row. The full function catalog is available in the expression editor sidebar.

Row-wise functions are always lower-case and calls are made using the function name followed by parentheses containing any arguments:

sqrt(4)                              # → 2
pow(abs(-sqrt(3.14**2)),2)           # → 3.14
if(TRUE, "true branch", "false")     # → "true branch"

Each function has a specific number of arguments and types that it expects. If the arguments do not match the expected types, a type error is raised. The return type of a function is determined by the function itself and is not necessarily the same as the input types.

Every function returns some value and there are no void functions. Functions can be nested, i.e., a function call can be an argument to another function. If there are multiple arguments, they must be separated by commas. Each argument can be any valid expression. You may optionally include a trailing comma after the last argument.

Aggregation functions operate on a whole column and return a single value usable in each row. They are prefixed with COLUMN_:

COLUMN_MIN("Price")
COLUMN_AVERAGE("Revenue", ignore_nan=TRUE)

The aggregation functions take a string literal "Column name" instead of a value from a row ($["column name"] or $column_name) as input.

In aggregation functions we offer to provide arguments positionally and by name of the argument. Positional arguments are always first, followed by named arguments. Named arguments are always provided as arg_name=value.

Let's illustrate that for the aggregation function COLUMN_AVERAGE(column, ignore_nan)

  • Only positional arguments: COLUMN_AVERAGE("Column Name", TRUE)
  • Only named arguments: COLUMN_AVERAGE(column="Column Name",ignore_nan=TRUE)
  • Mixed arguments: COLUMN_AVERAGE("Column Name", ignore_nan=TRUE,)

Operator precedence ​

From highest to lowest:

  1. ?? (missing coalescing)
  2. ** (exponentiation)
  3. Unary -
  4. *, /, %, //
  5. +, -
  6. <, <=, >, >=, !=, <>, =, ==
  7. not
  8. and
  9. or

Use parentheses to override precedence: (1 + 2) * 3 evaluates to 9, while 1 + 2 * 3 evaluates to 7.

Built-in constants ​

ConstantTypeValue
TRUE / FALSEBOOLEANBoolean truth values
EFLOATEuler's number (~2.71828)
PIFLOATπ (~3.14159)
INFINITYFLOATPositive infinity
NaNFLOATNot a Number
MAX_INTEGER / MIN_INTEGERINTEGERLargest / smallest 64-bit integer
MAX_FLOAT / MIN_FLOATFLOATLargest / smallest representable float
TINY_FLOATFLOATThe smallest positive representable float
MISSING—Missing value literal