OQL Functions Reference β‘
Functions Overview
Navigation
Use the Index below to jump to the details of a function.
π Date & Time
| Function | Purpose |
|---|---|
adjustTimeToInterval |
Snap a timestamp to the start or end of a named interval (e.g., shift). |
date_trunc |
Truncate a timestamp to the start of a bucket (s, m, h, D, W, M, Q, Y). |
timeinif |
Seconds within the interval where a condition holds true. |
toDateTime64 |
Format a timestamp as a date-time string with precision and timezone. |
toUnixTimestamp |
Date-time to Unix epoch seconds. |
age |
Calculate difference between two dates. |
addDays |
Add days to a date. |
addHours |
Add hours to a date. |
addMinutes |
Add minutes to a date. |
formatDateTime |
Format a date-time using a template. |
π Metric & Aggregate
| Function | Purpose |
|---|---|
abs |
Absolute value. |
avg |
Average of values. |
avgWeighted |
Duration-weighted average (alias for weighted avg). |
mean |
Alias for avg. |
avgIf |
Conditional average. |
boundingRatio |
Slope between first and last values over time. |
deltasum |
Sum of positive increments between consecutive points. |
durationWeightedAvg |
Durationβweighted average. |
exp |
e^x. |
first |
First value in range. |
firstIf |
First value meeting a condition. |
intDiv |
Integer division. |
last |
Last value in range. |
lastIf |
Last value meeting a condition. |
log |
Natural log. |
max |
Maximum value in a timeseries. |
metric |
Read a metric by UUID. |
metric_group |
Read a metric group by UUID. |
metric_group_metadata |
Read display metadata for a metric group. |
min |
Minimum value in a timeseries. |
mod |
Modulus (remainder). |
p05 |
5th percentile. |
p05If |
Conditional 5th percentile. |
p10 |
10th percentile. |
p10If |
Conditional 10th percentile. |
p20 |
20th percentile. |
p20If |
Conditional 20th percentile. |
p25 |
25th percentile. |
p25If |
Conditional 25th percentile. |
p50 |
Median (50th percentile). |
p50If |
Conditional median. |
p75 |
75th percentile. |
p75If |
Conditional 75th percentile. |
p80 |
80th percentile. |
p80If |
Conditional 80th percentile. |
p90 |
90th percentile. |
p90If |
Conditional 90th percentile. |
p95 |
95th percentile. |
p95If |
Conditional 95th percentile. |
p*TDigest |
Approximate quantiles using TDigest. |
p*TDigestIf |
Conditional TDigest quantiles. |
stddev |
Standard deviation. |
sum |
Sum of values. |
sum2 |
Sum of squares. |
sumIf |
Conditional sum. |
count |
Distinct count. |
countIf |
Conditional count on metrics, or interval count when not applied to a metric. |
date_diff |
Difference between two datetimes in a given unit. |
lag |
Previous row value (window function). |
lead |
Next row value (window function). |
β Math
| Function | Purpose |
|---|---|
coalesce |
First nonβnull value. |
greatest |
Largest of multiple values. |
least |
Smallest of multiple values. |
pow |
Power function. |
round |
Round to a decimal place or magnitude. |
sqrt |
Square root. |
floor |
Round down to nearest integer or decimal place. |
ceil |
Round up to nearest integer or decimal place. |
trunc |
Truncate to integer or decimal place. |
sign |
Sign of number (-1, 0, or 1). |
log10 |
Base-10 logarithm. |
log2 |
Base-2 logarithm. |
cbrt |
Cube root. |
clamp |
Constrain value to range. |
isFinite |
Check if number is finite. |
π Conditional
| Function | Purpose |
|---|---|
if |
If/else. |
multiIf |
Multiβbranch conditional. |
isNaN |
Is NaN. |
isNull |
Is null. |
isNotNull |
Not null. |
isZeroOrNull |
Is zero or null. |
π€ String
| Function | Purpose |
|---|---|
concat |
Concatenate strings. |
containsAny |
Contains any of the given values. |
like |
match with wildcards. |
match |
Regex match. |
left |
Left substring. |
right |
Right substring. |
substring |
Substring by position and length. |
length |
Length of string. |
π JSON
| Function | Purpose |
|---|---|
jsonExists |
Check if path exists in JSON. |
jsonQuery |
Extract object/array by path. |
jsonValue |
Extract scalar value by path. |
β»οΈ Type Conversion
| Function | Purpose |
|---|---|
cast |
Convert value to a type. |
castOrNull |
Safe cast (returns null if invalid). |
toString |
Convert to string. |
toInt32 |
Convert to 32-bit integer. |
toInt64 |
Convert to 64-bit integer. |
toFloat32 |
Convert to 32-bit float. |
toFloat64 |
Convert to 64-bit float. |
toDate |
Convert to date. |
π οΈ Misc
| Function | Purpose |
|---|---|
all |
Array of all values in interval. |
encodeURLComponent |
URLβsafe encoding. |
formatRow |
Format row output (CSV/TSV/JSONCompactEachRow). |
set |
List of unique values for metrics and intervals. |
has |
Array membership test. |
hasAny |
Array contains any of given values. |
hasAll |
Array contains all given values. |
exponentialTimeDecayedAvg |
Exponentially weighted moving average. |
| — |
Function Details
β’ adjustTimeToInterval
Snaps time to the boundary of interval (start or end). Useful for aligning queries to shifts or custom windows.
Arguments
| Name | Type | Description |
|---|---|---|
time |
DateTime | Input timestamp (e.g., now()). |
interval |
String | Interval descriptor (e.g., shift.start, shift.end). |
π‘ Example
where time from now() to adjustTimeToInterval(now(), shift.start)
π See also
date_trunc β’ toDateTime64 β’ toUnixTimestamp
β’ date_trunc
Rounds time down to the start of a given bucket (e.g., day or week).
Arguments
| Name | Type | Description |
|---|---|---|
time |
DateTime | Input timestamp (e.g., now()). |
bucket |
String | One of s, m, h, D, W, M, Q, Y. |
π‘ Example
where time from now() to date_trunc(now(),'D')
π See also
adjustTimeToInterval β’ toUnixTimestamp β’ toDateTime64
β’ timeinif
Counts the number of seconds in the current range where condition is true. With no arguments, returns the total query duration in seconds.
Arguments
| Name | Type | Description |
|---|---|---|
condition |
Boolean (optional) | Predicate evaluated over time. Omit for total window duration. |
π‘ Example
aggregate timeinif(interval.state.category.name = 'Uptime')
π See also
sumIf β’ avgIf β’ countIf
β’ toDateTime64
Converts timestamp to a DateTime with precision fractional seconds in timezone.
Arguments
| Name | Type | Description |
|---|---|---|
timestamp |
DateTime / UnixSeconds | Source timestamp (e.g., query.start). |
precision |
Integer | Fractional second precision (0β3). |
timezone |
String | IANA timezone (e.g., 'America/New_York'). |
Example
aggregate toDateTime64(query.start, 0, 'America/Los_Angeles')
π See also
toUnixTimestamp β’ date_trunc β’ adjustTimeToInterval
β’ toUnixTimestamp
Returns Unix seconds for a given date_time.
Arguments
| Name | Type | Description |
|---|---|---|
date_time |
DateTime | Input date-time (e.g., query.end). |
π‘ Example
aggregate toUnixTimestamp(query.end)
π See also
toDateTime64 β’ date_trunc β’ adjustTimeToInterval
β’ abs
Returns the nonβnegative value of expression.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Number / Timeseries | Input value. |
π‘ Example
aggregate abs(avg(metric_group('uuid')))
π See also
sqrt β’ pow β’ log
β’ avg
Computes the arithmetic mean of expression.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Number / Timeseries | Values to average. |
π‘ Example
aggregate avg(metric_group('uuid'))
π See also
avgIf β’ sum β’ count
β’ avgIf
Average of expression for rows where condition is true.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Number / Timeseries | Values to average. |
condition |
Boolean | Filter predicate. |
π‘ Example
aggregate avgIf(metric_group('uuid'), interval.state.category.name = 'Uptime')
π See also
avg β’ sumIf β’ countIf
β’ boundingRatio
Computes (last β first) Γ· (end_time β start_time) for expression.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Number / Timeseries | Series to evaluate. |
π‘ Example
aggregate boundingRatio(metric_group('uuid'))
π See also
deltasum β’ first β’ last
β’ deltasum
Sums positive increases of expression across time; ignores decreases.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Number / Timeseries | Monotonic or counter-like series. |
π‘ Example
aggregate deltasum(metric_group('uuid'))
π See also
sum β’ boundingRatio β’ countIf
β’ durationWeightedAvg
Definition
Averages expression with weights proportional to interval duration.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Number / Timeseries | Values to average with time weighting. |
π‘ Example
aggregate durationWeightedAvg(interval.run.performance_target.value)
π See also
avg β’ avgIf β’ sumIf
β’ exp
Raises Eulerβs number e to expression.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Number / Timeseries | Exponent input. |
π‘ Example
aggregate exp(last(metric_group('uuid')))
π See also
log β’ pow β’ sqrt
β’ first
Returns the earliest value of expression in the selected time range.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Any / Timeseries | Series or field. |
π‘ Example
aggregate first(metric_group('uuid'))
π See also
last β’ firstIf β’ coalesce
β’ firstIf
Returns the earliest expression where condition is true.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Any / Timeseries | Series or field. |
condition |
Boolean | Filter predicate. |
π‘ Example
aggregate firstIf(offline_quality.results.TEST_NAME, offline_quality.results.METADATA = 'X')
π See also
lastIf β’ first β’ coalesce
β’ intDiv
Divides lhs by rhs and truncates toward zero.
Arguments
| Name | Type | Description |
|---|---|---|
lhs |
Number | Dividend. |
rhs |
Number | Divisor (nonβzero). |
π‘ Example
aggregate intDiv(7, 2)
π See also
mod β’ round β’ pow
β’ last
Returns the most recent value of expression in the selected time range.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Any / Timeseries | Series or field. |
π‘ Example
aggregate last(metric_group('uuid'))
π See also
first β’ lastIf β’ coalesce
β’ lastIf
Returns the most recent expression where condition is true.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Any / Timeseries | Series or field. |
condition |
Boolean | Filter predicate. |
π‘ Example
aggregate lastIf(offline_quality.results.TEST_NAME, offline_quality.results.METADATA = 'X')
π See also
firstIf β’ last β’ coalesce
β’ log
Computes ln(expression).
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Number / Timeseries | Positive input value. |
π‘ Example
aggregate log(10)
π See also
exp β’ pow β’ sqrt
β’ max
Returns the largest value of expression over the range.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Number / Timeseries | Values to compare. |
π‘ Example
aggregate max(metric_group('uuid'))
π See also
min β’ greatest β’ p95
β’ metric
Fetches values of the metric identified by UUID.
Arguments
| Name | Type | Description |
|---|---|---|
uuid |
String | Metric identifier. |
π‘ Example
aggregate avg(metric('uuid'))
π See also
metric_group β’ avg
β’ metric_group
Fetches values of the metric group identified by UUID.
Arguments
| Name | Type | Description |
|---|---|---|
uuid |
String | Metric group identifier. |
π‘ Example
aggregate avg(metric_group('uuid'))
β’ metric_group_metadata
Returns display metadata (e.g., display name) for a metric group field.
Arguments
| Name | Type | Description |
|---|---|---|
field |
String | Metadata field key (e.g., 'performance'). |
π‘ Example
aggregate metric_group_metadata('performance').display_name
π See also
metric_group β’ toString β’ formatRow
β’ min
Returns the smallest value of expression over the range.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Number / Timeseries | Values to compare. |
π‘ Example
aggregate min(metric_group('uuid'))
π See also
max β’ least β’ p25
β’ mod
Returns the remainder of lhs divided by rhs.
Arguments
| Name | Type | Description |
|---|---|---|
lhs |
Number | Dividend. |
rhs |
Number | Divisor (nonβzero). |
π‘ Example
aggregate mod(7, 2)
π See also
intDiv β’ round β’ abs
β’ p05
Returns the 0.05 quantile of expression.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Number / Timeseries | Values to aggregate. |
π‘ Example
aggregate p05(metric_group('uuid'))
π See also
p05If β’ p25 β’ p*TDigest
β’ p05If
Returns the 5th percentile of expression where condition is true.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Number / Timeseries | Values to aggregate. |
condition |
Boolean | Filter predicate. |
π‘ Example
aggregate p05If(metric_group('uuid'), interval.state.category.name = 'Uptime')
π See also
p05 β’ p25If β’ p*TDigestIf
β’ p10
Returns the 0.10 quantile of expression.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Number / Timeseries | Values to aggregate. |
π‘ Example
aggregate p10(metric_group('uuid'))
π See also
p10If β’ p20 β’ p*TDigest
β’ p10If
Returns the 10th percentile of expression where condition is true.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Number / Timeseries | Values to aggregate. |
condition |
Boolean | Filter predicate. |
π‘ Example
aggregate p10If(metric_group('uuid'), interval.state.category.name = 'Uptime')
π See also
p10 β’ p20If β’ p*TDigestIf
β’ p20
Returns the 0.20 quantile of expression.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Number / Timeseries | Values to aggregate. |
π‘ Example
aggregate p20(metric_group('uuid'))
π See also
p20If β’ p25 β’ p*TDigest
β’ p20If
Returns the 20th percentile of expression where condition is true.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Number / Timeseries | Values to aggregate. |
condition |
Boolean | Filter predicate. |
π‘ Example
aggregate p20If(metric_group('uuid'), interval.state.category.name = 'Uptime')
π See also
p20 β’ p25If β’ p*TDigestIf
β’ p25
Returns the 0.25 quantile of expression.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Number / Timeseries | Values to aggregate. |
π‘ Example
aggregate p25(metric_group('uuid'))
π See also
p25If β’ p50 β’ p*TDigest
β’ p25If
Returns the 25th percentile of expression where condition is true.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Number / Timeseries | Values to aggregate. |
condition |
Boolean | Filter predicate. |
π‘ Example
aggregate p25If(metric_group('uuid'), interval.state.category.name = 'Uptime')
π See also
p25 β’ p50If β’ p*TDigestIf
β’ p50
Returns the median (0.5 quantile) of expression.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Number / Timeseries | Values to aggregate. |
π‘ Example
aggregate p50(metric_group('uuid'))
π See also
p50If β’ p25 β’ p75
β’ p50If
Returns the median of expression where condition is true.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Number / Timeseries | Values to aggregate. |
condition |
Boolean | Filter predicate. |
π‘ Example
aggregate p50If(metric_group('uuid'), interval.state.category.name = 'Uptime')
π See also
p50 β’ p25If β’ p75If
β’ p75
Returns the 0.75 quantile of expression.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Number / Timeseries | Values to aggregate. |
π‘ Example
aggregate p75(metric_group('uuid'))
π See also
p75If β’ p50 β’ p90
β’ p75If
Returns the 75th percentile where condition is true.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Number / Timeseries | Values to aggregate. |
condition |
Boolean | Filter predicate. |
π‘ Example
aggregate p75If(metric_group('uuid'), interval.state.category.name = 'Uptime')
π See also
p75 β’ p50If β’ p90If
β’ p80
Returns the 0.80 quantile of expression.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Number / Timeseries | Values to aggregate. |
π‘ Example
aggregate p80(metric_group('uuid'))
π See also
p80If β’ p75 β’ p90
β’ p80If
Returns the 80th percentile where condition is true.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Number / Timeseries | Values to aggregate. |
condition |
Boolean | Filter predicate. |
π‘ Example
aggregate p80If(metric_group('uuid'), interval.state.category.name = 'Uptime')
π See also
p80 β’ p75If β’ p90If
β’ p90
Returns the 0.90 quantile of expression.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Number / Timeseries | Values to aggregate. |
π‘ Example
aggregate p90(metric_group('uuid'))
π See also
p90If β’ p75 β’ p95
β’ p90If
Returns the 90th percentile where condition is true.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Number / Timeseries | Values to aggregate. |
condition |
Boolean | Filter predicate. |
π‘ Example
aggregate p90If(metric_group('uuid'), interval.state.category.name = 'Uptime')
π See also
p90 β’ p75If β’ p95If
β’ p95
Returns the 0.95 quantile of expression.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Number / Timeseries | Values to aggregate. |
π‘ Example
aggregate p95(metric_group('uuid'))
π See also
p95If β’ p90 β’ p*TDigest
β’ p95If
Returns the 95th percentile where condition is true.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Number / Timeseries | Values to aggregate. |
condition |
Boolean | Filter predicate. |
π‘ Example
aggregate p95If(metric_group('uuid'), interval.state.category.name = 'Uptime')
π See also
p95 β’ p90If β’ p*TDigestIf
β’ p*TDigest
Approximate pβquantiles (p25TDigest, p75TDigest) for expression using TDigest (memoryβefficient).
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Number / Timeseries | Values to aggregate. |
π‘ Example
aggregate p75TDigest(metric_group('uuid'))
π See also
p*TDigestIf β’ p75 β’ p90
β’ p*TDigestIf
Approximate pβquantiles (p25TDigestIf, p75TDigestIf) for rows where condition is true.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Number / Timeseries | Values to aggregate. |
condition |
Boolean | Filter predicate. |
π‘ Example
aggregate p90TDigestIf(metric_group('uuid'), interval.state.category.name = 'Uptime')
π See also
p*TDigest β’ p90If β’ p75If
β’ pow
Computes base raised to exponent.
Arguments
| Name | Type | Description |
|---|---|---|
base |
Number | Base value. |
exponent |
Number | Exponent. |
π‘ Example
aggregate pow(metric_group('uuid'), 3)
π See also
exp β’ sqrt β’ log
β’ round
Rounds value to digits decimal places (negative digits round to tens/hundreds).
Arguments
| Name | Type | Description |
|---|---|---|
value |
Number | Input value. |
digits |
Integer | Decimal places; may be negative. |
π‘ Example
aggregate round(metric_group('uuid'), -1)
π See also
intDiv β’ mod β’ pow
β’ sqrt
Returns the principal square root of value.
Arguments
| Name | Type | Description |
|---|---|---|
value |
Number | Nonβnegative input. |
π‘ Example
aggregate sqrt(metric_group('uuid'))
π See also
pow β’ abs β’ log
β’ stddev
Returns the standard deviation of expression.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Number / Timeseries | Values to aggregate. |
π‘ Example
aggregate stddev(metric_group('uuid'))
π See also
avg β’ sum2 β’ p95
β’ sum
Sums all values of expression.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Number / Timeseries | Values to sum. |
π‘ Example
aggregate sum(metric_group('uuid'))
π See also
sumIf β’ sum2 β’ avg
β’ sum2
Sums the squares of values in expression.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Number / Timeseries | Values to square and sum. |
π‘ Example
aggregate sum2(metric_group('uuid'))
π See also
sum β’ stddev β’ avg
β’ sumIf
Sums values of expression where condition is true.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Number / Timeseries | Values to sum. |
condition |
Boolean | Filter predicate. |
π‘ Example
aggregate sumIf(metric_group('uuid'), interval.state.category.name = 'Uptime')
π See also
sum β’ avgIf β’ countIf
β’ coalesce
Returns the first nonβnull of its arguments; otherwise returns the fallback.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Any | Primary value. |
fallback |
Any | Returned if primary is null (same type). |
π‘ Example
aggregate coalesce(last(metric_group('uuid')), 0)
π See also
first β’ last β’ toString
β’ count
Counts the number of unique values of expression.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Any / Timeseries | Values to deduplicate and count. |
π‘ Example
aggregate count(interval.run.name)
π See also
countIf β’ sum β’ set
β’ countIf
Behavior depends on the first argument:
countIf(metric('uuid'), condition)orcountIf(metric_group('uuid'), condition)β counts metric data points whereconditionis true.countIf(condition)orcountIf(interval.run.name, condition)(non-metric first arg) β counts intervals matching the condition.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Metric or interval (optional) | Metric/interval context for point counting. |
condition |
Boolean | Filter predicate. |
π‘ Example
aggregate countIf(interval.run.name, interval.state.type = 'Uptime')
π See also
count β’ sumIf β’ avgIf
β’ greatest
Returns the maximum from a list of constants/expressions.
Arguments
| Name | Type | Description |
|---|---|---|
value1, value2, ... |
Number | Two or more inputs. |
π‘ Example
aggregate greatest(avg(metric_group('uuid')), 1.23, 0)
π See also
least β’ max β’ coalesce
β’ least
Returns the minimum from a list of constants/expressions.
Arguments
| Name | Type | Description |
|---|---|---|
value1, value2, ... |
Number | Two or more inputs. |
π‘ Example
aggregate least(avg(metric_group('uuid')), 1.23, 0)
π See also
greatest β’ min β’ coalesce
β’ if
Returns then_value if condition is true; otherwise else_value.
Arguments
| Name | Type | Description |
|---|---|---|
condition |
Boolean | Predicate. |
then_value |
Any | Result if true. |
else_value |
Any | Result if false. |
π‘ Example
aggregate if(avg(metric_group('uuid')) > 1, 'ok', 'low')
π See also
multiIf β’ coalesce β’ isNull
β’ multiIf
Evaluates pairs of (condition, value) in order; returns the first match, else the final default value.
Arguments
| Name | Type | Description |
|---|---|---|
condition1, value1, ... |
Mixed | One or more condition/value pairs, plus default. |
π‘ Example
aggregate multiIf(x>10,'high', x>5,'mid', 'low')
π See also
if β’ coalesce β’ isNull
β’ isNaN
Returns 1 if expression is not-a-number, else 0.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Number | Numeric input. |
π‘ Example
aggregate isNaN(avg(metric_group('uuid')))
π See also
isNull β’ isNotNull β’ if
β’ isNull
Returns 1 if expression is null, else 0.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Any | Input value. |
π‘ Example
aggregate isNull(last(metric_group('uuid')))
π See also
isNotNull β’ coalesce β’ if
β’ isNotNull
Returns 1 if expression is not null, else 0.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Any | Input value. |
π‘ Example
aggregate isNotNull(last(metric_group('uuid')))
π See also
isNull β’ coalesce β’ if
β’ isZeroOrNull
Returns 1 if expression equals 0 or is null; otherwise 0.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Number / Any | Input value. |
π‘ Example
aggregate isZeroOrNull(avg(metric_group('uuid')))
π See also
isNull β’ isNotNull β’ if
β’ concat
Concatenates arguments leftβtoβright into a single string.
Arguments
| Name | Type | Description |
|---|---|---|
value1, value2, ... |
String / Any | Values converted to string and concatenated. |
π‘ Example
aggregate concat('Product ', toString(metric('uuid')))
π See also
formatRow β’ toString β’ match
β’ containsAny
Returns true if string contains at least one of the provided values.
Arguments
| Name | Type | Description |
|---|---|---|
string |
String | Source text. |
values |
String list | One or more substrings to search for. |
π‘ Example
where containsAny(interval.state.comment, 'alarm','reset','fault')
π See also
like β’ match β’ concat
β’ like
Returns 1 if value matches the LIKE pattern (e.g., %substr%).
Arguments
| Name | Type | Description |
|---|---|---|
value |
String | Source text. |
pattern |
String | LIKE pattern with % and _. |
π‘ Example
aggregate like(product.name, '%Widget%')
π See also
match β’ containsAny β’ concat
β’ match
Returns 1 if value matches the regular expression regex.
Arguments
| Name | Type | Description |
|---|---|---|
value |
String | Source text. |
regex |
String | Regular expression (e.g., '[0-9]*-03'). |
π‘ Example
aggregate match(product.name, '[0-9]*-03')
π See also
like β’ containsAny β’ concat
β’ left
Returns the leftmost length characters of string.
Arguments
| Name | Type | Description |
|---|---|---|
string |
String | Source text. |
length |
Integer | Number of characters to return. |
π‘ Example
aggregate left(product.name, 5)
π See also
right β’ substring β’ concat
β’ right
Returns the rightmost length characters of string.
Arguments
| Name | Type | Description |
|---|---|---|
string |
String | Source text. |
length |
Integer | Number of characters to return. |
π‘ Example
aggregate right(product.name, 5)
π See also
left β’ substring β’ concat
β’ substring
Returns a substring of string starting at start for length characters.
substr is an alias. If starting position is negative, counts from the end
of the string.
Arguments
| Name | Type | Description |
|---|---|---|
string |
String | Source text. |
start |
Integer | Starting position (1-based). |
length |
Integer | Number of characters to return. |
π‘ Example
aggregate substring(product.name, 2, 4)
π See also
left β’ right β’ concat
β’ length
Returns the number of characters in string.
Arguments
| Name | Type | Description |
|---|---|---|
string |
String | Source text. |
π‘ Example
aggregate length(product.name)
π See also
left β’ right β’ concat
β’ jsonExists
Returns 1 if an object exists at path in object, else 0.
Arguments
| Name | Type | Description |
|---|---|---|
object |
JSON | JSON document. |
path |
String | JSONPath (e.g., '$.field'). |
π‘ Example
aggregate jsonExists(metadata, '$.config.version')
π See also
jsonValue β’ jsonQuery β’ isNotNull
β’ jsonQuery
Extract any JSON object, array, or sub-structure from a JSON object using a JSONPath. jsonQuery returns any JSON structure at the given path β objects, arrays, lists, or mixed types. If the path matches multiple elements, the function returns an array of matches. Use it to retrieve a complex structure and further process it.
Arguments
| Name | Type | Description |
|---|---|---|
object |
JSON | The JSON document (stringified or native JSON). |
path |
String | JSONPath expression (supports wildcards and array indices). |
π‘ Example
1. Extract a sub-object
aggregate jsonQuery(metadata, '$.path')
2. Extract several array indices
aggregate jsonQuery(metadata, '$.path[*][0,1,2]')
π See also
jsonValue β’ jsonExists
β’ jsonValue
Extract a single scalar (string, number, boolean) from a JSON object. If the path matches multiple elements, only the first is returned.
Arguments
| Name | Type | Description |
|---|---|---|
object |
JSON/Array | JSON document or array (including output from jsonQuery). |
path |
String | JSONPath pointing to a scalar. |
π‘ Example
1. Extract a scalar
aggregate jsonValue(metadata, '$.path')
2. Extract from a particular array index
aggregate jsonValue(metadata, '$.path[1][0]')
π See also
jsonQuery β’ jsonExists β’ toString
β’ cast
Casts value to type and returns the converted value.
Arguments
| Name | Type | Description |
|---|---|---|
value |
Any | Value to cast. |
type |
String | Target type (e.g., 'Float64'). |
π‘ Example
aggregate cast('1.23','Float64')
π See also
castOrNull β’ toString β’ coalesce
β’ castOrNull
Attempts to cast value to type; returns null if not possible.
Arguments
| Name | Type | Description |
|---|---|---|
value |
Any | Value to cast. |
type |
String | Target type (e.g., 'Float64'). |
π‘ Example
aggregate castOrNull(metadata.field, 'Float64')
π See also
cast β’ toString β’ coalesce
β’ toString
Converts expression to a string representation.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Any | Value to stringify. |
π‘ Example
aggregate toString(metric_group('uuid'))
π See also
formatRow β’ concat β’ cast
β’ all
Returns an array of every value that expression takes within the range.
Arguments
| Name | Type | Description |
|---|---|---|
expression |
Any / Timeseries | Series or field. |
π‘ Example
aggregate all(interval.state.type)
π See also
count β’ formatRow β’ set
β’ encodeURLComponent
Encodes a string for safe use in URLs (percentβencoding).
Arguments
| Name | Type | Description |
|---|---|---|
string |
String | Text to encode. |
π‘ Example
aggregate encodeURLComponent(concat('SOP ', toString(query.start)))
π See also
concat β’ toString β’ formatRow
β’ formatRow
Formats one or more expression values into a single formatted cell.
Arguments
| Name | Type | Description |
|---|---|---|
format |
String | One of CSV, TSV, JSONCompactEachRow. |
expression... |
Any | One or more values to format. |
π‘ Example
aggregate formatRow('CSV', metric('uuid'), avg(metric_group('uuid')))
π See also
concat β’ toString
β’ set
Returns a set of unique values for expression (interval or metrics).
Arguments
| Name | Type | Description |
|---|---|---|
expression... |
Any / Timeseries | Values to deduplicate. |
π‘ Example
aggregate set(metric_group('uuid'))
β’ floor
Rounds value down to the largest number less than or equal to it, optionally to N decimal places.
Arguments
| Name | Type | Description |
|---|---|---|
value |
Number | Input value. |
N |
Integer | Optional decimal places (default 0). |
π‘ Example
aggregate floor(avg(metric_group('uuid')), 2)
π See also
ceil β’ trunc β’ round
β’ ceil
Rounds value up to the smallest number greater than or equal to it, optionally to N decimal places. ceiling is an alias.
Arguments
| Name | Type | Description |
|---|---|---|
value |
Number | Input value. |
N |
Integer | Optional decimal places (default 0). |
π‘ Example
aggregate ceil(avg(metric_group('uuid')), 1)
π See also
floor β’ trunc β’ round
β’ trunc
Truncates value to the number with the largest absolute value less than or equal to it, optionally to N decimal places. truncate is an alias.
Arguments
| Name | Type | Description |
|---|---|---|
value |
Number | Input value. |
N |
Integer | Optional decimal places (default 0). |
π‘ Example
aggregate trunc(avg(metric_group('uuid')), 1)
π See also
floor β’ ceil β’ round
β’ sign
Returns the sign of value: -1 for negative, 0 for zero, 1 for positive.
Arguments
| Name | Type | Description |
|---|---|---|
value |
Number | Input value. |
π‘ Example
aggregate sign(avg(metric_group('uuid')))
π See also
abs β’ if β’ greatest
β’ log10
Returns the base-10 logarithm of value.
Arguments
| Name | Type | Description |
|---|---|---|
value |
Number | Positive input value. |
π‘ Example
aggregate log10(avg(metric_group('uuid')))
π See also
log β’ log2 β’ exp
β’ log2
Returns the base-2 logarithm of value.
Arguments
| Name | Type | Description |
|---|---|---|
value |
Number | Positive input value. |
π‘ Example
aggregate log2(avg(metric_group('uuid')))
π See also
log β’ log10 β’ exp
β’ cbrt
Returns the cube root of value.
Arguments
| Name | Type | Description |
|---|---|---|
value |
Number | Input value. |
π‘ Example
aggregate cbrt(avg(metric_group('uuid')))
π See also
sqrt β’ pow β’ abs
β’ clamp
Constrains value to be within the range [min, max].
Arguments
| Name | Type | Description |
|---|---|---|
value |
Number | Input value. |
min |
Number | Minimum bound. |
max |
Number | Maximum bound. |
π‘ Example
aggregate clamp(avg(metric_group('uuid')), 0, 100)
π See also
greatest β’ least β’ if
β’ isFinite
Returns 1 if value is finite (not infinite or NaN), else 0.
Arguments
| Name | Type | Description |
|---|---|---|
value |
Number | Input value. |
π‘ Example
aggregate isFinite(avg(metric_group('uuid')))
π See also
isNaN β’ isNull β’ if
β’ age
Calculates the difference between enddate and startdate in the specified unit.
Arguments
| Name | Type | Description |
|---|---|---|
unit |
String | One of ‘microsecond’, ‘millisecond’, ‘second’, ‘minute’, ‘hour’, ‘day’, ‘week’, ‘month’, ‘quarter’, ‘year’. |
startdate |
DateTime | Start date/time. |
enddate |
DateTime | End date/time. |
π‘ Example
aggregate age('hour', query.start, query.end)
π See also
addDays β’ addHours β’ date_trunc
β’ addDays
Adds num days to datetime.
Arguments
| Name | Type | Description |
|---|---|---|
datetime |
DateTime | Input date/time. |
num |
Integer | Number of days to add (can be negative). |
π‘ Example
aggregate addDays(query.start, 7)
π See also
age β’ addHours β’ addMinutes
β’ addHours
Adds num hours to datetime.
Arguments
| Name | Type | Description |
|---|---|---|
datetime |
DateTime | Input date/time. |
num |
Integer | Number of hours to add (can be negative). |
π‘ Example
aggregate addHours(query.start, 8)
π See also
age β’ addDays β’ addMinutes
β’ addMinutes
Adds num minutes to datetime.
Arguments
| Name | Type | Description |
|---|---|---|
datetime |
DateTime | Input date/time. |
num |
Integer | Number of minutes to add (can be negative). |
π‘ Example
aggregate addMinutes(query.start, 30)
π See also
age β’ addDays β’ addHours
β’ formatDateTime
Formats datetime according to format string (e.g., %Y-%m-%d).
Arguments
| Name | Type | Description |
|---|---|---|
datetime |
DateTime | Input date/time. |
format |
String | Format string, see abbreviations below |
timezone (optional) |
String | Timezone for formatting (e.g., ‘UTC’, ‘America/Los_Angeles’). Defaults to query timezone. |
| Abbreviation | Description |
|---|---|
%a |
Abbreviated weekday name (Sun..Sat) |
%b |
Abbreviated month name (Jan..Dec) |
%c |
Month, numeric (0..12) |
%D |
Day of the month with English suffix (0th, 1st, 2nd, 3rd, β¦) |
%d |
Day of the month, numeric (00..31) |
%e |
Day of the month, numeric (0..31) |
%f |
Microseconds (000000..999999) |
%H |
Hour (00..23) |
%h |
Hour (01..12) |
%I |
Hour (01..12) |
%i |
Minutes, numeric (00..59) |
%j |
Day of year (001..366) |
%k |
Hour (0..23) |
%l |
Hour (1..12) |
%M |
Month name (January..December) |
%m |
Month, numeric (00..12) |
%p |
AM or PM |
%r |
Time, 12-hour (hh:mm:ss followed by AM or PM) |
%S |
Seconds (00..59) |
%s |
Seconds (00..59) |
%T |
Time, 24-hour (hh:mm:ss) |
%U |
Week (00..53), where Sunday is the first day of the week; WEEK() mode 0 |
%u |
Week (00..53), where Monday is the first day of the week; WEEK() mode 1 |
%V |
Week (01..53), where Sunday is the first day of the week; WEEK() mode 2; used with %X |
%v |
Week (01..53), where Monday is the first day of the week; WEEK() mode 3; used with %x |
%W |
Weekday name (Sunday..Saturday) |
%w |
Day of the week (0=Sunday..6=Saturday) |
%X |
Year for the week where Sunday is the first day of the week, numeric, four digits; used with %V |
%x |
Year for the week, where Monday is the first day of the week, numeric, four digits; used with %v |
%Y |
Year, numeric, four digits |
%y |
Year, numeric (two digits) |
%% |
A literal % character |
π‘ Example
aggregate formatDateTime(toDateTime64('2022-01-01 03:03:03', 3), '%M')
β’ toInt32
Converts value to a 32-bit signed integer, truncating fractional digits.
Arguments
| Name | Type | Description |
|---|---|---|
value |
Any | Value to convert. |
π‘ Example
aggregate toInt32(avg(metric_group('uuid')))
π See also
toInt64 β’ toFloat64 β’ cast
β’ toInt64
Converts value to a 64-bit signed integer, truncating fractional digits.
Arguments
| Name | Type | Description |
|---|---|---|
value |
Any | Value to convert. |
π‘ Example
aggregate toInt64(avg(metric_group('uuid')))
π See also
toInt32 β’ toFloat64 β’ cast
β’ toFloat32
Converts value to a 32-bit floating point number.
Arguments
| Name | Type | Description |
|---|---|---|
value |
Any | Value to convert. |
π‘ Example
aggregate toFloat32(metric_group('uuid'))
π See also
toFloat64 β’ toInt32 β’ cast
β’ toFloat64
Converts value to a 64-bit floating point number.
Arguments
| Name | Type | Description |
|---|---|---|
value |
Any | Value to convert. |
π‘ Example
aggregate toFloat64(metric_group('uuid'))
π See also
toFloat32 β’ toInt64 β’ cast
β’ toDate
Converts value to a Date type.
Arguments
| Name | Type | Description |
|---|---|---|
value |
Any | Value to convert (string, datetime, or timestamp). |
π‘ Example
aggregate toDate(query.start)
π See also
toDateTime64 β’ toUnixTimestamp β’ cast
β’ date_diff
Returns the difference between two datetimes in the given unit.
Arguments
| Name | Type | Description |
|---|---|---|
unit |
String | One of s, m, h, D, W, M, Q, Y. |
start |
DateTime | Start timestamp. |
end |
DateTime | End timestamp. |
π‘ Example
aggregate date_diff('h', query.start, query.end) as query_hours
where time from now()-7D to now()
β’ lag / β’ lead
Window-only aggregates that return the previous (lag) or next (lead) value in a window partition. Use with OVER window_name. Returns 0 when no previous/next row exists.
π‘ Example
aggregate lag(metric_group('uuid')) over w as prev_value
where time from now()-1D to now()
window w as (partition by line.id order by timestamp)
π See also Window Functions