Flux v0.111.0 (#2394)

* added flux-0.111 release notes

* Flux TICKscript package (#2388)

* WIP tickscript package

* WIP tickscript pkg

* fleshed out tickscript pkg

* added introduction version to flux pkg

* updated to address PR feedback

* fixed output typos

* duplicated tickscript package to cloud
pull/2395/head
Scott Anderson 2021-04-07 11:33:46 -06:00 committed by GitHub
parent 866292bde8
commit ff97e554a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 1074 additions and 6 deletions

View File

@ -74,7 +74,7 @@ All previous writes are now stored in cold shards.
influxd-ctl truncate-shards
```
The expected ouput of this command is:
The expected output of this command is:
```
Truncated shards.
@ -302,7 +302,7 @@ All previous writes are now stored in cold shards.
influxd-ctl truncate-shards
```
The expected ouput of this command is:
The expected output of this command is:
```
Truncated shards.

View File

@ -74,7 +74,7 @@ All previous writes are now stored in cold shards.
influxd-ctl truncate-shards
```
The expected ouput of this command is:
The expected output of this command is:
```
Truncated shards.
@ -302,7 +302,7 @@ All previous writes are now stored in cold shards.
influxd-ctl truncate-shards
```
The expected ouput of this command is:
The expected output of this command is:
```
Truncated shards.

View File

@ -77,7 +77,7 @@ All previous writes are now stored in cold shards.
influxd-ctl truncate-shards
```
The expected ouput of this command is:
The expected output of this command is:
```
Truncated shards.
@ -305,7 +305,7 @@ All previous writes are now stored in cold shards.
influxd-ctl truncate-shards
```
The expected ouput of this command is:
The expected output of this command is:
```
Truncated shards.

View File

@ -0,0 +1,17 @@
---
title: Flux TICKscript package
list_title: TICKscript package
description: >
The Flux TICKscript package provides functions to help migrate Kapacitor TICKscripts to Flux tasks.
Import the `contrib/bonitoo-io/tickscript` package.
menu:
influxdb_cloud_ref:
name: TICKscript
parent: Contributed
weight: 202
influxdb/v2.0/tags: [functions, tickscript, package]
cascade:
introduced: 0.111.0
---
{{< duplicate-oss >}}

View File

@ -0,0 +1,17 @@
---
title: tickscript.alert() function
description: >
The `tickscript.alert()` function function identifies events of varying severity levels
and writes them to the `statuses` measurement in the InfluxDB
`_monitoring` system bucket.
menu:
influxdb_cloud_ref:
name: tickscript.alert
parent: TICKscript
weight: 302
related:
- /{{< latest "kapacitor" >}}/nodes/alert_node/, Kapacitor AlertNode
introduced: 0.111.0
---
{{< duplicate-oss >}}

View File

@ -0,0 +1,17 @@
---
title: tickscript.compute() function
description: >
The `tickscript.compute()` function is an alias for `tickscript.select()` that
changes a column's name and optionally applies an aggregate or selector function
to values in the column.
menu:
influxdb_cloud_ref:
name: tickscript.compute
parent: TICKscript
weight: 302
related:
- /influxdb/cloud/reference/flux/stdlib/contrib/tickscript/select/
- /{{< latest "kapacitor" >}}/nodes/query_node/
---
{{< duplicate-oss >}}

View File

@ -0,0 +1,16 @@
---
title: tickscript.deadman() function
description: >
The `tickscript.deadman()` function detects low data throughput and writes a point
with a critical status to the InfluxDB `_monitoring` system bucket.
menu:
influxdb_cloud_ref:
name: tickscript.deadman
parent: TICKscript
weight: 302
related:
- /{{< latest "kapacitor" >}}/nodes/batch_node/#deadman, Kapacitor BatchNode  Deadman
introduced: 0.111.0
---
{{< duplicate-oss >}}

View File

@ -0,0 +1,14 @@
---
title: tickscript.defineCheck() function
description: >
The `tickscript.defineCheck()` function creates and returns a record with custom
check data required by `tickscript.alert()` and `tickscript.deadman()`.
menu:
influxdb_cloud_ref:
name: tickscript.defineCheck
parent: TICKscript
weight: 302
introduced: 0.111.0
---
{{< duplicate-oss >}}

View File

@ -0,0 +1,15 @@
---
title: tickscript.groupBy() function
description: >
The `tickscript.groupBy()` function groups results by the `_measurement` column
and other specified columns.
menu:
influxdb_cloud_ref:
name: tickscript.groupBy
parent: TICKscript
weight: 302
related:
- /{{< latest "kapacitor" >}}/nodes/query_node/#groupby, Kapacitor QueryNode - groupBy
---
{{< duplicate-oss >}}

View File

@ -0,0 +1,16 @@
---
title: tickscript.join() function
description: >
The `tickscript.join()` function merges two input streams into a single output
stream based on specified columns with equal values and appends a new measurement name.
menu:
influxdb_cloud_ref:
name: tickscript.join
parent: TICKscript
weight: 302
related:
- /{{< latest "kapacitor" >}}/nodes/join_node/, Kapacitor JoinNode
- /influxdb/cloud/reference/flux/stdlib/built-in/transformations/join/
---
{{< duplicate-oss >}}

View File

@ -0,0 +1,17 @@
---
title: tickscript.select() function
description: >
The `tickscript.select()` function changes a column's name and optionally applies
an aggregate or selector function to values in the column.
menu:
influxdb_cloud_ref:
name: tickscript.select
parent: TICKscript
weight: 302
related:
- /influxdb/cloud/reference/flux/stdlib/contrib/tickscript/selectwindow/
- /{{< latest "kapacitor" >}}/nodes/query_node/
introduced: 0.111.0
---
{{< duplicate-oss >}}

View File

@ -0,0 +1,17 @@
---
title: tickscript.selectWindow() function
description: >
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.
menu:
influxdb_cloud_ref:
name: tickscript.selectWindow
parent: TICKscript
weight: 302
related:
- /influxdb/cloud/reference/flux/stdlib/contrib/tickscript/select/
- /{{< latest "kapacitor" >}}/nodes/query_node/
introduced: 0.111.0
---
{{< duplicate-oss >}}

View File

@ -0,0 +1,31 @@
---
title: Flux TICKscript package
list_title: TICKscript package
description: >
The Flux TICKscript package provides functions to help migrate Kapacitor TICKscripts to Flux tasks.
Import the `contrib/bonitoo-io/tickscript` package.
menu:
influxdb_2_0_ref:
name: TICKscript
parent: Contributed
weight: 202
influxdb/v2.0/tags: [functions, tickscript, package]
cascade:
introduced: 0.111.0
---
The Flux TICKscript package provides functions to help migrate Kapacitor TICKscripts to Flux tasks.
Import the `contrib/bonitoo-io/tickscript` package:
```js
import "contrib/bonitoo-io/tickscript"
```
## Functions
{{< children type="functions" show="pages" >}}
{{% note %}}
#### Package author and maintainer
**Github:** [@bonitoo-io](https://github.com/bonitoo-io), [@alespour](https://github.com/alespour)
**InfluxDB Slack:** [@Ales Pour](https://influxdata.com/slack)
{{% /note %}}

View File

@ -0,0 +1,144 @@
---
title: tickscript.alert() function
description: >
The `tickscript.alert()` function function identifies events of varying severity levels
and writes them to the `statuses` measurement in the InfluxDB
`_monitoring` system bucket.
menu:
influxdb_2_0_ref:
name: tickscript.alert
parent: TICKscript
weight: 302
related:
- /{{< latest "kapacitor" >}}/nodes/alert_node/, Kapacitor AlertNode
introduced: 0.111.0
---
The `tickscript.alert()` function identifies events of varying severity levels
and writes them to the `statuses` measurement in the InfluxDB
[`_monitoring` system bucket](/influxdb/v2.0/reference/internals/system-buckets/).
_This function is comparable to the [Kapacitor AlertNode](/{{< latest "kapacitor" >}}/nodes/alert_node/)._
```js
import "contrib/bonitoo-io/tickscript"
tickscript.alert(
check,
id: (r) => "${r._check_id}",
details: (r) => "",
message: (r) => "Threshold Check: ${r._check_name} is: ${r._level}",
crit: (r) => false,
warn: (r) => false,
info: (r) => false,
ok: (r) => true,
topic: ""
)
```
## Parameters
### check
({{< req >}})
InfluxDB check data.
_See [`tickscript.defineCheck()`](/influxdb/v2.0/reference/flux/stdlib/contrib/tickscript/definecheck/)._
_**Data type:** Record_
### id
Function that returns the InfluxDB check ID provided by the [`check` record](#check).
Default is `(r) => "${r._check_id}"`.
_**Data type:** Function_
### details
Function to return the InfluxDB check details using data from input rows.
Default is `(r) => ""`.
_**Data type:** Function_
### message
Function to return the InfluxDB check message using data from input rows.
Default is `(r) => "Threshold Check: ${r._check_name} is: ${r._level}"`.
_**Data type:** Function_
### crit
Predicate function to determine `crit` status.
Default is `(r) => false`
_**Data type:** Function_
### warn
Predicate function to determine `warn` status.
Default is `(r) => false`
_**Data type:** Function_
### info
Predicate function to determine `info` status.
Default is `(r) => false`
_**Data type:** Function_
### ok
Predicate function to determine `ok` status.
Default is `(r) => true`
_**Data type:** Function_
### topic
Check topic.
Default is `""`
_**Data type:** String_
## Examples
##### Store alert statuses for error counts
{{< code-tabs-wrapper >}}
{{% code-tabs %}}
[Flux](#)
[TICKscript](#)
{{% /code-tabs %}}
{{% code-tab-content %}}
```javascript
import "contrib/bonitoo-io/tickscript"
option task = {name: "Example task", every: 1m;}
from(bucket: "example-bucket")
|> range(start: -task.every)
|> filter(fn: (r) => r._measurement == "errors" and r._field == "value")
|> count()
|> tickscript.alert(
check: tickscript.defineCheck(id: "000000000000", name: "task/${r.service}"),
message: "${r._check_name} is ${r._level} value: ${r._value}",
crit: (r) => r._value > 30,
warn: (r) => r._value > 20,
info: (r) => r._value > 10
)
```
{{% /code-tab-content %}}
{{% code-tab-content %}}
```javascript
data = batch
|query('SELECT count(value) from errors')
.every(1m)
data
|alert()
.id('kapacitor/{{ index .Tags "service" }}')
.message('{{ .ID }} is {{ .Level }} value:{{ index .Fields "value" }}')
.info(lambda: "value" > 10)
.warn(lambda: "value" > 20)
.crit(lambda: "value" > 30)
```
{{% /code-tab-content %}}
{{< /code-tabs-wrapper >}}
{{% note %}}
#### Package author and maintainer
**Github:** [@bonitoo-io](https://github.com/bonitoo-io), [@alespour](https://github.com/alespour)
**InfluxDB Slack:** [@Ales Pour](https://influxdata.com/slack)
{{% /note %}}

View File

@ -0,0 +1,73 @@
---
title: tickscript.compute() function
description: >
The `tickscript.compute()` function is an alias for `tickscript.select()` that
changes a column's name and optionally applies an aggregate or selector function
to values in the column.
menu:
influxdb_2_0_ref:
name: tickscript.compute
parent: TICKscript
weight: 302
related:
- /influxdb/v2.0/reference/flux/stdlib/contrib/tickscript/select/
- /{{< latest "kapacitor" >}}/nodes/query_node/
---
The `tickscript.compute()` function is an **alias for
[`tickscript.select()`](/influxdb/v2.0/reference/flux/stdlib/contrib/tickscript/select/)**
that changes a column's name and optionally applies an aggregate or selector function.
```js
import "contrib/bonitoo-io/tickscript"
tickscript.compute(
column: "_value",
fn: sum,
as: "example-name"
)
```
#### TICKscript helper function
`tickscript.select()` is a helper function meant to replicate TICKscript operations
like the following:
```js
// Rename
query("SELECT x AS y")
// Aggregate and rename
query("SELECT f(x) AS y")
```
## Parameters
### column
Column to operate on.
Default is `_value`.
_**Data type:** String_
### fn
[Aggregate](/influxdb/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/)
or [selector](/influxdb/v2.0/reference/flux/stdlib/built-in/transformations/selectors/)
function to apply.
_**Data type:** Function_
### as
({{< req >}})
New column name.
_**Data type:** String_
## Examples
For examples, see [`tickscript.select()`](/influxdb/v2.0/reference/flux/stdlib/contrib/tickscript/select/#examples).
{{% note %}}
#### Package author and maintainer
**Github:** [@bonitoo-io](https://github.com/bonitoo-io), [@alespour](https://github.com/alespour)
**InfluxDB Slack:** [@Ales Pour](https://influxdata.com/slack)
{{% /note %}}

View File

@ -0,0 +1,120 @@
---
title: tickscript.deadman() function
description: >
The `tickscript.deadman()` function detects low data throughput and writes a point
with a critical status to the InfluxDB `_monitoring` system bucket.
menu:
influxdb_2_0_ref:
name: tickscript.deadman
parent: TICKscript
weight: 302
related:
- /{{< latest "kapacitor" >}}/nodes/batch_node/#deadman, Kapacitor BatchNode  Deadman
introduced: 0.111.0
---
The `tickscript.deadman()` function detects low data throughput and writes a point
with a critical status to the InfluxDB [`_monitoring` system bucket](/influxdb/v2.0/reference/internals/system-buckets/).
For each input table containing a number of rows less than or equal to the specified
[threshold](#threshold), the function assigns a `crit` value to the `_level` column.
_This function is comparable to the [Kapacitor AlertNode deadman](/{{< latest "kapacitor" >}}/nodes/alert_node/#deadman)._
```js
import "contrib/bonitoo-io/tickscript"
tickscript.deadman(
check: {},
measurement: "example-measurement",
threshold: 0,
id: (r)=>"${r._check_id}",
message: (r) => "Deadman Check: ${r._check_name} is: " + (if r.dead then "dead" else "alive"),
topic: ""
)
```
## Parameters
### check
({{< req >}})
InfluxDB check data.
_See [`tickscript.defineCheck()`](/influxdb/v2.0/reference/flux/stdlib/contrib/tickscript/definecheck/)._
_**Data type:** Record_
### measurement
({{< req >}})
Measurement name.
Should match the queried measurement.
_**Data type:** String_
### threshold
Count threshold.
The function assigns a `crit` status to input tables with a number of rows less
than or equal to the threshold.
Default is `0`.
_**Data type:** Integer_
### id
Function that returns the InfluxDB check ID provided by the [`check` record](#check).
Default is `(r) => "${r._check_id}"`.
_**Data type:** Function_
### message
Function that returns the InfluxDB check message using data from input rows.
Default is `(r) => "Deadman Check: ${r._check_name} is: " + (if r.dead then "dead" else "alive")`.
_**Data type:** Function_
### topic
Check topic.
Default is `""`.
_**Data type:** String_
## Examples
{{< code-tabs-wrapper >}}
{{% code-tabs %}}
[Flux](#)
[TICKscript](#)
{{% /code-tabs %}}
{{% code-tab-content %}}
```javascript
import "contrib/bonitoo-io/tickscript"
option task = {name: "Example task", every: 1m;}
from(bucket: "example-bucket")
|> range(start: -task.every)
|> filter(fn: (r) => r._measurement == "pulse" and r._field == "value")
|> tickscript.deadman(
check: tickscript.defineCheck(id: "000000000000", name: "task/${r.service}"),
measurement: "pulse",
threshold: 2
)
```
{{% /code-tab-content %}}
{{% code-tab-content %}}
```javascript
data = batch
|query('SELECT value from pulse')
.every(1m)
data
|deadman(2.0, 1m)
.id('kapacitor/{{ index .Tags "service" }}')
.message('{{ .ID }} is {{ .Level }} value:{{ index .Fields "value" }}')
```
{{% /code-tab-content %}}
{{< /code-tabs-wrapper >}}
{{% note %}}
#### Package author and maintainer
**Github:** [@bonitoo-io](https://github.com/bonitoo-io), [@alespour](https://github.com/alespour)
**InfluxDB Slack:** [@Ales Pour](https://influxdata.com/slack)
{{% /note %}}

View File

@ -0,0 +1,78 @@
---
title: tickscript.defineCheck() function
description: >
The `tickscript.defineCheck()` function creates and returns a record with custom
check data required by `tickscript.alert()` and `tickscript.deadman()`.
menu:
influxdb_2_0_ref:
name: tickscript.defineCheck
parent: TICKscript
weight: 302
introduced: 0.111.0
---
The `tickscript.defineCheck()` function creates and returns a record with custom check data required by
[`tickscript.alert()`](/influxdb/v2.0/reference/flux/stdlib/contrib/tickscript/alert/) and
[`tickscript.deadman()`](/influxdb/v2.0/reference/flux/stdlib/contrib/tickscript/deadman/).
This check data specifies information about the check in the InfluxDB monitoring system.
```js
import "contrib/bonitoo-io/tickscript"
tickscript.defineCheck(
id: "000000000000",
name: "Example check name",
type: "custom"
)
```
## Parameters
## id
({{< req >}})
InfluxDB check ID.
_**Data type:** String_
## name
({{< req >}})
InfluxDB check name.
_**Data type:** String_
## type
InfluxDB check type.
Default is `custom`.
_**Data type:** String_
**Supported values:**
- threshold
- deadman
- custom
## Examples
##### Generate InfluxDB check data
```javascript
import "contrib/bonitoo-io/tickscript"
tickscript.defineCheck(
id: "000000000000",
name: "Example check name",
)
// The function above returns: {
// _check_id: "000000000000",
// _check_name: "Example check name",
// _type: "custom",
// tags: {}
// }
```
{{% note %}}
#### Package author and maintainer
**Github:** [@bonitoo-io](https://github.com/bonitoo-io), [@alespour](https://github.com/alespour)
**InfluxDB Slack:** [@Ales Pour](https://influxdata.com/slack)
{{% /note %}}

View File

@ -0,0 +1,58 @@
---
title: tickscript.groupBy() function
description: >
The `tickscript.groupBy()` function groups results by the `_measurement` column
and other specified columns.
menu:
influxdb_2_0_ref:
name: tickscript.groupBy
parent: TICKscript
weight: 302
related:
- /{{< latest "kapacitor" >}}/nodes/query_node/#groupby, Kapacitor QueryNode - groupBy
---
The `tickscript.groupBy()` function groups results by the `_measurement` column and
other specified columns.
_This function is comparable to [Kapacitor QueryNode .groupBy](/{{< latest "kapacitor" >}}/nodes/query_node/#groupby)._
{{% note %}}
To group by intervals of time, use [`window()`](/influxdb/v2.0/reference/flux/stdlib/built-in/transformations/window/)
or [`tickscript.selectWindow()`](/influxdb/v2.0/reference/flux/stdlib/contrib/tickscript/selectwindow/).
{{% /note %}}
```js
import "contrib/bonitoo-io/tickscript"
tickscript.groupBy(
columns: ["exampleColumn"]
)
```
## Parameters
### columns
({{< req >}})
List of columns to group by.
_**Data type:** Array of Strings_
## Examples
##### Group by host and region
```js
import "contrib/bonitoo-io/tickscript"
data
|> tickscript.groupBy(
columns: ["host", "region"]
)
```
{{% note %}}
#### Package author and maintainer
**Github:** [@bonitoo-io](https://github.com/bonitoo-io), [@alespour](https://github.com/alespour)
**InfluxDB Slack:** [@Ales Pour](https://influxdata.com/slack)
{{% /note %}}

View File

@ -0,0 +1,121 @@
---
title: tickscript.join() function
description: >
The `tickscript.join()` function merges two input streams into a single output
stream based on specified columns with equal values and appends a new measurement name.
menu:
influxdb_2_0_ref:
name: tickscript.join
parent: TICKscript
weight: 302
related:
- /{{< latest "kapacitor" >}}/nodes/join_node/, Kapacitor JoinNode
- /influxdb/v2.0/reference/flux/stdlib/built-in/transformations/join/
---
The `tickscript.join()` function merges two input streams into a single output
stream based on specified columns with equal values and appends a new measurement name.
_This function is comparable to the [Kapacitor JoinNode](/{{< latest "kapacitor" >}}/nodes/join_node/)._
```js
import "contrib/bonitoo-io/tickscript"
tickscript.join(
tables: {t1: example1, t2: example2}
on: ["_time"],
measurement: "example-measurement"
)
```
## Parameters
### tables
({{< req >}})
Map of two streams to join.
_**Data type:** Record_
### on
List of columns to join on.
Default is `["_time"]`.
_**Data type:** Array of Strings_
### measurement
({{< req >}})
Measurement name to use in results.
_**Data type:** Array of Strings_
## Examples
### Join two streams of data
#### Input data
{{< flex >}}
{{% flex-content %}}
##### metrics
| _time | host | _value |
|:----- |:---- | ------:|
| 2021-01-01T00:00:00Z | host1 | 1.2 |
| 2021-01-01T01:00:00Z | host1 | 0.8 |
| 2021-01-01T02:00:00Z | host1 | 3.2 |
| _time | host | _value |
|:----- |:---- | ------:|
| 2021-01-01T00:00:00Z | host2 | 8.4 |
| 2021-01-01T01:00:00Z | host2 | 7.3 |
| 2021-01-01T02:00:00Z | host2 | 7.9 |
{{% /flex-content %}}
{{% flex-content %}}
##### states
| _time | host | _value |
|:----- |:---- | ------:|
| 2021-01-01T00:00:00Z | host1 | dead |
| 2021-01-01T01:00:00Z | host1 | dead |
| 2021-01-01T02:00:00Z | host1 | alive |
| _time | host | _value |
|:----- |:---- | ------:|
| 2021-01-01T00:00:00Z | host2 | alive |
| 2021-01-01T01:00:00Z | host2 | alive |
| 2021-01-01T02:00:00Z | host2 | alive |
{{% /flex-content %}}
{{< /flex >}}
#### Query
```js
import "contrib/bonitoo-io/tickscript"
metrics = //...
states = //...
tickscript.join(
tables: {metric: metrics, state: states},
on: ["_time", "host"],
measurement: "example-m"
)
```
#### Output data
| _measurement | host | _time | _value_metric | _value_state |
|:------------ |:---- |:----- | -------------:| ------------:|
| example-m | host1 | 2021-01-01T00:00:00Z | 1.2 | dead |
| example-m | host1 | 2021-01-01T01:00:00Z | 0.8 | dead |
| example-m | host1 | 2021-01-01T02:00:00Z | 3.2 | alive |
| _measurement | host | _time | _value_metric | _value_state |
|:------------ |:---- |:----- | -------------:| ------------:|
| example-m | host2 | 2021-01-01T00:00:00Z | 8.4 | alive |
| example-m | host2 | 2021-01-01T01:00:00Z | 7.3 | alive |
| example-m | host2 | 2021-01-01T02:00:00Z | 7.9 | alive |
{{% note %}}
#### Package author and maintainer
**Github:** [@bonitoo-io](https://github.com/bonitoo-io), [@alespour](https://github.com/alespour)
**InfluxDB Slack:** [@Ales Pour](https://influxdata.com/slack)
{{% /note %}}

View File

@ -0,0 +1,165 @@
---
title: tickscript.select() function
description: >
The `tickscript.select()` function changes a column's name and optionally applies
an aggregate or selector function to values in the column.
menu:
influxdb_2_0_ref:
name: tickscript.select
parent: TICKscript
weight: 302
related:
- /influxdb/v2.0/reference/flux/stdlib/contrib/tickscript/selectwindow/
- /{{< latest "kapacitor" >}}/nodes/query_node/
introduced: 0.111.0
---
The `tickscript.select()` function changes a column's name and optionally applies
an aggregate or selector function to values in the column.
```js
import "contrib/bonitoo-io/tickscript"
tickscript.select(
column: "_value",
fn: sum,
as: "example-name"
)
```
#### TICKscript helper function
`tickscript.select()` is a helper function meant to replicate TICKscript operations
like the following:
```js
// Rename
query("SELECT x AS y")
// Aggregate and rename
query("SELECT f(x) AS y")
```
## Parameters
### column
Column to operate on.
Default is `_value`.
_**Data type:** String_
### fn
[Aggregate](/influxdb/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/)
or [selector](/influxdb/v2.0/reference/flux/stdlib/built-in/transformations/selectors/)
function to apply.
_**Data type:** Function_
### as
({{< req >}})
New column name.
_**Data type:** String_
## Examples
- [Change the name of the value column](#change-the-name-of-the-value-column)
- [Change the name of the value column and apply an aggregate function](#change-the-name-of-the-value-column-and-apply-an-aggregate-function)
- [Change the name of the value column and apply a selector function](#change-the-name-of-the-value-column-and-apply-a-selector-function)
---
#### Change the name of the value column
```js
import "contrib/bonitoo-io/tickscript"
data
|> tickscript.select(as: "example-name")
```
{{< flex >}}
{{% flex-content %}}
##### Input data
| _time | _value |
|:----- | ------:|
| 2021-01-01T00:00:00Z | 1.2 |
| 2021-01-01T01:00:00Z | 3.2 |
| 2021-01-01T02:00:00Z | 4.0 |
{{% /flex-content %}}
{{% flex-content %}}
##### Output data
| _time | example-name |
|:----- | ------------:|
| 2021-01-01T00:00:00Z | 1.2 |
| 2021-01-01T01:00:00Z | 3.2 |
| 2021-01-01T02:00:00Z | 4.0 |
{{% /flex-content %}}
{{< /flex >}}
---
#### Change the name of the value column and apply an aggregate function
```js
import "contrib/bonitoo-io/tickscript"
data
|> tickscript.select(
as: "sum",
fn: sum
)
```
{{< flex >}}
{{% flex-content %}}
##### Input data
| _time | _value |
|:----- | ------:|
| 2021-01-01T00:00:00Z | 1.2 |
| 2021-01-01T01:00:00Z | 3.2 |
| 2021-01-01T02:00:00Z | 4.0 |
{{% /flex-content %}}
{{% flex-content %}}
##### Output data
| sum |
|:---:|
| 8.4 |
{{% /flex-content %}}
{{< /flex >}}
---
#### Change the name of the value column and apply a selector function
```js
import "contrib/bonitoo-io/tickscript"
data
|> tickscript.select(
as: "max",
fn: max
)
```
{{< flex >}}
{{% flex-content %}}
##### Input data
| _time | _value |
|:----- | ------:|
| 2021-01-01T00:00:00Z | 1.2 |
| 2021-01-01T01:00:00Z | 3.2 |
| 2021-01-01T02:00:00Z | 4.0 |
{{% /flex-content %}}
{{% flex-content %}}
##### Output data
| _time | max |
|:----- | ---:|
| 2021-01-01T02:00:00Z | 4.0 |
{{% /flex-content %}}
{{< /flex >}}
---
{{% note %}}
#### Package author and maintainer
**Github:** [@bonitoo-io](https://github.com/bonitoo-io), [@alespour](https://github.com/alespour)
**InfluxDB Slack:** [@Ales Pour](https://influxdata.com/slack)
{{% /note %}}

View File

@ -0,0 +1,120 @@
---
title: tickscript.selectWindow() function
description: >
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.
menu:
influxdb_2_0_ref:
name: tickscript.selectWindow
parent: TICKscript
weight: 302
related:
- /influxdb/v2.0/reference/flux/stdlib/contrib/tickscript/select/
- /{{< latest "kapacitor" >}}/nodes/query_node/
introduced: 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.
```js
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:
```js
// 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](/influxdb/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/)
or [selector](/influxdb/v2.0/reference/flux/stdlib/built-in/transformations/selectors/)
function to apply.
_**Data type:** Function_
### as
({{< req >}})
New column name.
_**Data type:** String_
### every
({{< req >}})
Duration of windows.
_**Data type:** Duration_
### defaultValue
({{< req >}})
Default fill value for null values in [`column`](#column).
_Must be the same data type as `column`._
_**Data type:** String | Boolean | Float | Integer | Uinteger | Bytes_
## Examples
#### Change the name of, window, and then aggregate the value column
```js
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 >}}
{{% note %}}
#### Package author and maintainer
**Github:** [@bonitoo-io](https://github.com/bonitoo-io), [@alespour](https://github.com/alespour)
**InfluxDB Slack:** [@Ales Pour](https://influxdata.com/slack)
{{% /note %}}

View File

@ -8,6 +8,18 @@ menu:
name: Flux
---
## v0.111.0 [2021-03-30]
### Features
- Use `FnvHasher` for hash maps.
- Add [`tickscript` package](/influxdb/v2.0/reference/flux/stdlib/contrib/tickscript/).
### Bug fixes
- When finding the parent directory's root, skip the current directory.
- Fix `if else` statement in `aggregate.window()`.
---
## v0.109.1 [2021-03-24]
### Bug fixes