2.8 KiB
2.8 KiB
title | description | menu | weight | aliases | related | flux/v0.x/tags | introduced | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
tickscript.selectWindow() function | The `tickscript.selectWindow()` function changes a column's name, windows rows by time, and applies an aggregate or selector function the specified column for each window of time. |
|
302 |
|
|
|
0.111.0 |
The tickscript.selectWindow()
function changes a column's name, windows rows by time,
and applies an aggregate or selector function the specified column for each window of time.
import "contrib/bonitoo-io/tickscript"
tickscript.selectWindow(
column: "_value",
fn: sum,
as: "example-name",
every: 1m,
defaultValue: 0.0,
)
TICKscript helper function
tickscript.selectWindow()
is a helper function meant to replicate TICKscript operations
like the following:
// Rename, window, and aggregate
query("SELECT f(x) AS y")
.groupBy(time(t), ...)
Parameters
column
Column to operate on.
Default is _value
.
Data type: String
fn
({{< req >}}) Aggregate or selector function to apply.
as
({{< req >}}) New column name.
every
({{< req >}}) Duration of windows.
defaultValue
({{< req >}})
Default fill value for null values in column
.
Must be the same data type as column
.
tables
Input data.
Default is piped-forward data (<-
).
Examples
Change the name of, window, and then aggregate the value column
import "contrib/bonitoo-io/tickscript"
data
|> tickscript.selectWindow(
fn: sum,
as: "example-name",
every: 1h,
defaultValue: 0.0,
)
{{< flex >}} {{% flex-content %}}
Input data
_time | _value |
---|---|
2021-01-01T00:00:00Z | 1.2 |
2021-01-01T00:30:00Z | 0.8 |
2021-01-01T01:00:00Z | 3.2 |
2021-01-01T01:30:00Z | 3.9 |
2021-01-01T02:00:00Z | |
2021-01-01T02:30:00Z | 3.3 |
{{% /flex-content %}} | |
{{% flex-content %}} |
Output data
_time | example-name |
---|---|
2021-01-01T00:59:59 | 2.0 |
2021-01-01T01:59:59 | 7.1 |
2021-01-01T02:59:59 | 3.3 |
{{% /flex-content %}} | |
{{< /flex >}} |