Enso's Expression Syntax
Enso's expression syntax is a simple, yet powerful, way to manipulate data in Enso. It is designed to be familiar to those used to writing SQL formulas or Excel table based functions.
This guide gives and overview of the syntax a summary of the functions currently avaialble.
To enter an expression, choose the <Expression>
entry from the dropdown. They can be used in many places where a column is used, such as in a filter
or aggregate
components.
Currently, it is not possible to use Enso literals inside the expression syntax but this is planned for a later release.
How to use this guide
In the documentation below, you will see Enso functions with examples. This text plugs into Enso components that accept expressions including the set
, filter
and aggregate
.
An example may show:
IF [CATEGORY] = 1 THEN 'Elite' ELSE IF [CATEGORY] = 2 THEN 'Premium' ELSE 'Standard'
Below is how this function would appear in a set
component:
For simple examples below, such as year(2024-07-04)
returns 2024
, the date shown implies a value from a row in a DATE
column.
Below is how this function would appear in a set
component:
Functions can also be combined together to create much more complex expressions. For example:
if ([Age] > 20) AND ([State] IN ('NY', 'CO', 'CA')) then 'Target Customer' else 'Disqualify'
Below is how this expression would appear in a set
component:
Syntax description
The Expression syntax is similar to that of SQL Server syntax. The key features of the syntax are:
- Unlike in Enso code, whitespace is ignored.
- Expressions are case-insenstive for all identifiers, except for column names.
- Functions are invoked with argument lists in parentheses.
- The function name is case-insensitive.
- The first argument of the function is the column to operate on.
- Some functions allow for a variable number of arguments, for example
coalesce
andis_in
. - No support for comments within the expression (at least for version 1).
Literals
The following literals are supported:
- Nothing:
null
ornothing
(not case sensitive). - Boolean:
true
,false
(not case sensitive). - Number: Support for
_
separators in numbers. No support for hex, octal or binary literals. - Text: Two formats supported:
- If in double-quotes, then Excel style with only
""
as an escape sequence for"
. For example:"This is a ""quoted"" string with 'another'."
. - If in single quotes, then Python style with usual supported escapes. For example:
'This is a "quoted" string with \'another\'.'
.
- If in double-quotes, then Excel style with only
- Date: Should be written in ISO format, e.g.
2020-01-01
surrounded by#
characters. For example,#2020-01-01#
. - Time: Should be written in ISO format, e.g.
14:00:00
surrounded by#
characters. For example,#14:00:00#
.- Seconds are optional, so
#12:00#
is also valid.
- Seconds are optional, so
- Parts of seconds are optional allowing more precise specification, so
#12:00:00.123#
is also valid. - DateTime: Enso uses ISO format yyyy-mm-dd HH:MM:SS to represent dates and times. To use a date constant in a function, it needs to be specified as an ISO formatted date, surrounded by
#
characters. For example, 15, April 2020 at 2PM would be represented as#2020-15-04T14:00:00#
.- As with Time, seconds and part of seconds are optional.
- Time zone offset is also optional allowing users to specify a shift from UTC.
Additionally, the name of the TimeZone can be specified in[]
brackets either after the offset or on its own.
If no time zone or offset is passed the local system time zone will be used. Enso uses the ISO format yyyy-mm-dd HH:MM:SS to represent dates and times. If a DateTime value is not in this format, Enso reads it as a char. To convert a column to enable the use of the DateTime functions, use theparse
component to do so.
Column Names
Columns are represented by their name in square brackets, e.g. [First Name]
- Any closing brackets in the name need to be escaped (by being doubled) if it is part of the column name.
e.g.[First]] Name]
refers to a column namedFirst] Name
. - Column names will be case-sensitive (unless the backing table allows case-insensitive column names).
- The column name must be in square brackets.
- The escaping of
]
is based on the Alteryx syntax.
Note: this is different to SQLite, MySQL and Postgres, which use "
to identify columns. However, this is consistent with SQL Server, Excel, Tableau and Alteryx syntaxes.
Operators
The following operators are supported:
- Arithmetic:
+
,-
,*
,/
,%
(modulo),^
(power),-
(unary minus). - Comparison:
=
,!=
(and<>
),>
,>=
,<
,<=
.- Note:
=
and==
are equivalent as there is no assignment operation in the expression syntax.
- Note:
- Logical:
and
,or
,not
(and!
). - String:
+
(concatenation). - Date:
+
(addition of period),-
(subtraction of period),-
(subtraction of another date to a duration). - Time:
+
(addition of a duration),-
(subtraction of a duration),-
(subtraction of a time). - DateTime:
+
(addition of duration or period),-
(subtraction of duration or period),-
(subtraction of another date to a duration).
Additional special operators:
IS NULL
for checking if a value is null.IS EMPTY
for checking if a value is null or""
.LIKE
for comparing against SQL patterns.IN (...)
for checking if a value is in a list of values.<input> BETWEEN <lower> AND <upper>
for checking if a value is between two values
Precedence
The following specifies the operator precedence. Operators at the same level have the same precedence and are evaluated left to right.
-
(unary minus)^
(power)*
,/
,%
+
,-
=
,!=
(or<>
),>
,>=
,<
,<=
IS NULL
,IS NOT NULL
,IS EMPTY
,IS NOT EMPTY
,LIKE
,NOT LIKE
,IN (...)
,NOT IN (...)
,BETWEEN <lower> AND <upper>
NOT
(or!
)AND
OR
The precedence ensures that expressions are evaluated in the expected order (following the PEDMAS rules). For example, a + b * c
would be evaluated as a + (b * c)
.
Please note, that whitespace does not affect the precedence of operators.
Conditional Functions
A conditional function performs an action or calculation based on a test of data using an IF statement. Use a conditional function to provide a TRUE or FALSE result to highlight or filter out data based on specific criteria. Conditional functions can be used with any data type.
IF condition THEN true ELSE false ENDIF
-
IF <condition> THEN <true> ELSE <false>
. Returns<true>
if the<condition>
is true, else returns<false>
. -
There must be an
ELSE
clause, this is not optional. -
You may optionally include an
ENDIF
(orEND
) at the end of the statement.Example:
IF [CATEGORY] = 1 THEN 'Elite' ELSE 'Standard'
CATEGORY Result 2 Standard 1 Elite 1 Elite 3 Standard
IF condition1 THEN true1 ELSE IF condition2 THEN true2 ELSE false ENDIF
IF <condition1> THEN <true1> ELSE IF <condition2> THEN <true2> ELSE <false> ENDIF.
: Returns <true1>
if the first condition <condition1>
is true, else returns <true2>
if the second condition <condition2>
is true, else returns <false>
.
-
Multiple ELSE IF statements can be included.
-
There must be an
ELSE
clause, this is not optional. -
You may optionally include an
ENDIF
(orEND
) at the end of the statement.Example:
IF [CATEGORY] = 1 THEN 'Elite' ELSE IF [CATEGORY] = 2 THEN 'Premium' ELSE 'Standard'
CATEGORY Result 2 Premium 1 Elite 1 Elite 3 Standard