Time series functions
Below functions are designed to be used with timeSeries*()
aggregate functions like
timeSeriesInstantRateToGrid,
timeSeriesLastToGrid,
and so on.
timeSeriesRange
Generates a range of timestamps.
Syntax
Arguments
start_timestamp
- Start of the range.end_timestamp
- End of the range.step
- Step of the range in seconds.
Returned value
- Returns a range of timestamps
[start_timestamp, start_timestamp + step, start_timestamp + 2 * step, ..., end_timestamp]
.
Examples
Query:
Result:
Notes
- If function
timeSeriesRange()
is called withstart_timestamp
equal toend_timestamp
then it returns a 1-element array containing that timestamp:[start_timestamp]
- Function
timeSeriesRange()
is similar to function range. For example, if the type of timestamps isDateTime64(3)
andstart_timestamp < end_timestamp
thentimeSeriesRange(start_timestamp, end_timestamp, step)
returns the same result as the following expression:
timeSeriesFromGrid
Converts array of values [value1, value2, value3, ..., valueN]
to array of tuples
[(start_timestamp, value1), (start_timestamp + step, value2), (start_timestamp + 2 * step, value3), ..., (end_timestamp, valueN)]
.
If some of the values [value1, value2, value3, ...]
are NULL
then the function won't copy such null values to the result array
but will still increase the current timestamp, i.e. for example for [value1, NULL, value2]
the function will return
[(start_timestamp, value1), (start_timestamp + 2 * step, value2)]
.
The current timestamp is increased by step until it becomes greater than end_timestamp, each timestamp will be combined with a value from a specified array of values. If number of the values doesn't match number of the timestamps the function will throw an exception.
Syntax
Arguments
start_timestamp
- Start of the grid.end_timestamp
- End of the grid.step
- Step of the grid in seconds.values
- Array of values[value1, value2, ..., valueN]
.
Returned value
- Returns values from the source array of values combined with timestamps on a regular time grid described by
start_timestamp
andstep
.
Examples
Query:
Result:
Note
Function timeSeriesFromGrid(start_timestamp, end_timestamp, step, values)
returns the same result as the following expression:
seriesDecomposeSTL
Introduced in: v24.1
Decomposes a series data using STL (Seasonal-Trend Decomposition Procedure Based on Loess) into a season, a trend and a residual component.
Syntax
Arguments
series
— An array of numeric valuesArray((U)Int8/16/32/64)
orArray(Float*)
period
— A positive integerUInt8/16/32/64
Returned value
Returns an array of four arrays where the first array includes seasonal components, the second array - trend, the third array - residue component, and the fourth array - baseline(seasonal + trend) component. Array(Array(Float32), Array(Float32), Array(Float32), Array(Float32))
Examples
Decompose series data using STL
seriesOutliersDetectTukey
Introduced in: v24.2
Detects outliers in series data using Tukey Fences.
Syntax
Arguments
series
— An array of numeric values.Array((UInt8/16/32/64))
orArray(Float*)
min_percentile
— Optional. The minimum percentile to be used to calculate inter-quantile range (IQR). The value must be in range [0.02,0.98]. The default is 0.25.Float*
max_percentile
— Optional. The maximum percentile to be used to calculate inter-quantile range (IQR). The value must be in range [0.02,0.98]. The default is 0.75.Float*
K
— Optional. Non-negative constant value to detect mild or stronger outliers. The default value is 1.5.Float*
Returned value
Returns an array of the same length as the input array where each value represents score of possible anomaly of corresponding element in the series. A non-zero score indicates a possible anomaly. Array(Float32)
Examples
Basic outlier detection
Custom parameters outlier detection
seriesPeriodDetectFFT
Introduced in: v23.12
Finds the period of the given series data using FFT - Fast Fourier transform
Syntax
Arguments
series
— An array of numeric values.Array((U)Int8/16/32/64)
orArray(Float*)
Returned value
Returns a real value equal to the period of series data. NaN when number of data points are less than four. Float64
Examples
Period detection with simple pattern
Period detection with complex pattern
timeSeriesFromGrid
Introduced in: v25.8
Converts an array of values [x1, x2, x3, ...]
to an array of tuples
[(start_timestamp, x1), (start_timestamp + step, x2), (start_timestamp + 2 * step, x3), ...]
.
The current timestamp is increased by step
until it becomes greater than end_timestamp
If the number of the values doesn't match the number of the timestamps, the function throws an exception.
NULL values in [x1, x2, x3, ...]
are skipped but the current timestamp is still incremented.
For example, for [value1, NULL, x2]
the function returns [(start_timestamp, x1), (start_timestamp + 2 * step, x2)]
.
Syntax
Arguments
start_timestamp
— Start of the grid.DateTime64
orDateTime
orUInt32
end_timestamp
— End of the grid.DateTime64
orDateTime
orUInt32
step
— Step of the grid in secondsDecimal64
orDecimal32
orUInt32/64
values
— Array of valuesArray(Float*)
orArray(Nullable(Float*))
Returned value
Returns values from the source array of values combined with timestamps on a regular time grid described by start_timestamp
and step
. Array(Tuple(DateTime64, Float64))
Examples
Usage example
timeSeriesIdToTags
Introduced in: v25.8
Finds tags associated with the specified identifier of a time series.
Syntax
Arguments
id
— Identifier of a time series.UInt64
orUInt128
orUUID
orFixedString(16)
Returned value
Returns an array of pairs (tag_name, tag_value). Array(Tuple(String, String))
Examples
Example
timeSeriesIdToTagsGroup
Introduced in: v25.8
Converts the specified identifier of a time series to its group index. Group indices are numbers 0, 1, 2, 3 associated with each unique set of tags in the context of the currently executed query.
Syntax
Arguments
id
— Identifier of a time series.UInt64
orUInt128
orUUID
orFixedString(16)
Returned value
Returns a group index associated with this set of tags. UInt64
Examples
Example
timeSeriesRange
Introduced in: v25.8
Generates a range of timestamps [start_timestamp, start_timestamp + step, start_timestamp + 2 * step, ..., end_timestamp].
If start_timestamp
is equal to end_timestamp
, the function returns a 1-element array containing [start_timestamp]
.
Function timeSeriesRange()
is similar to function range.
Syntax
Arguments
start_timestamp
— Start of the range.DateTime64
orDateTime
orUInt32
end_timestamp
— End of the range.DateTime64
orDateTime
orUInt32
step
— Step of the range in secondsUInt32/64
orDecimal32/64
Returned value
Returns a range of timestamps. Array(DateTime64)
Examples
Usage example
timeSeriesStoreTags
Introduced in: v25.8
Stores mapping between the identifier of a time series and its tags in the query context, so that function timeSeriesIdToTags() can extract these tags later.
Syntax
Arguments
id
— Identifier of a time series.UInt64
orUInt128
orUUID
orFixedString(16)
tags_array
— Array of pairs (tag_name, tag_value).Array(Tuple(String, String))
orNULL
separate_tag_name_i
— The name of a tag.String
orFixedString
separate_tag_value_i
— The value of a tag.String
orFixedString
orNullable(String)
Returned value
Returns the first argument, i.e. the identifier of a time series.
Examples
Example
timeSeriesTagsGroupToTags
Introduced in: v25.8
Finds tags associated with a group index. Group indices are numbers 0, 1, 2, 3 associated with each unique set of tags in the context of the currently executed query.
Syntax
Arguments
group
— Group index associated with a time series.UInt64
Returned value
Array of pairs (tag_name, tag_value). Array(Tuple(String, String))
Examples
Example