Conditional functions
Functions that return a conditional result.
coalesce
Returns the first non-null
argument, if any, otherwise null
.
-
Syntax
coalesce(expression, …)
-
Parameters
Name Type Mandatory Default Constraints Description expression
array, boolean, double, duration, ip, long, record, string, timeframe, timestamp
yes
Returned if previous arguments are null.
-
Example
1data record(a = "a", b = "b", c = "c"),2 record(b = "b", c = "c"),3 record(c = "c"),4 record()5| fieldsAdd coalesce(a, b, c)Query result
a b c coalesce(a, b, c) a
b
c
a
null
b
c
b
null
null
c
c
null
null
null
null
if
Evaluates the condition, and returns the value of either the then or else parameter, depending on whether the condition evaluated to true (then) or false or null (else - or null if the else parameter is missing).
-
Syntax
if(condition, then [, else])
-
Parameters
Name Type Mandatory Default Constraints Description condition
boolean
yes
The condition to check.
then
array, boolean, double, duration, ip, long, record, string, timeframe, timestamp
yes
The expression if the condition is true.
else
array, boolean, double, duration, ip, long, record, string, timeframe, timestamp
no
The expression if the condition is false or null.
-
Example
1data record(a = 10),2 record(a = 20)3| fieldsAdd if(a < 15, "a is smaller than 15"),4 if(a < 15, "a is smaller than 15", else: "a is not smaller than 15")Query result
a if(a < 15, "a is smaller than 15") if(a < 15, "a is smaller than 15", else:"a is not smaller than 15") 10
a is smaller than 15
a is smaller than 15
20
null
a is not smaller than 15