docs-v2/content/flux/v0.x/stdlib/contrib/bonitoo-io/tickscript/selectwindow.md

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.
flux_0_x_ref
name parent
tickscript.selectWindow tickscript
302
/influxdb/v2.0/reference/flux/stdlib/contrib/tickscript/selectwindow/
/influxdb/cloud/reference/flux/stdlib/contrib/tickscript/selectwindow/
/flux/v0.x/stdlib/contrib/bonitoo-io/tickscript/select/
/{{< latest "kapacitor" >}}/nodes/query_node/
transformations
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 >}}