Merge pull request #776 from influxdata/flux/exp-aggr-pkg

Flux experimental aggregate package
pull/777/head
Scott Anderson 2020-02-21 13:49:03 -07:00 committed by GitHub
commit c8b058a9e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 99 additions and 0 deletions

View File

@ -0,0 +1,22 @@
---
title: Flux Aggregate package
list_title: Aggregate package
description: >
The Flux Aggregate package provides functions to simplify common aggregate operations.
Import the `experimental/aggregate` package.
menu:
v2_0_ref:
name: Aggregate
parent: Experimental
weight: 201
v2.0/tags: [package]
---
The Flux Aggregate package provides functions to simplify common aggregate operations.
Import the `experimental/aggregate` package:
```js
import "experimental/aggregate"
```
{{< children type="functions" show="pages" >}}

View File

@ -0,0 +1,77 @@
---
title: aggregate.rate() function
description: >
The `aggregate.rate()` function calculates the rate of change per windows of time.
menu:
v2_0_ref:
name: aggregate.rate
parent: Aggregate
weight: 301
---
The `aggregate.rate()` function calculates the rate of change per windows of time.
_**Function type:** Transformation_
```js
import "experimental/query"
aggregate.rate(
every: 1m,
groupColumns: ["column1", "column2"],
unit: 1s
)
```
## Parameters
### every
Duration of time windows.
_**Data type:** Duration_
### groupColumns
List of columns to group by. Defaults to `[]`.
_**Data type:** Array of strings_
### unit
The time duration to use when calculating the rate. Defaults to `1s`.
_**Data type:** Duration_
## Examples
```js
import "experimental/aggregate"
from(bucket: "example-bucket")
|> range(start: -1h)
|> aggregate.rate(every: 5m, unit: 1m)
```
## Function definition
```js
package aggregate
import "experimental"
rate = (tables=<-, every, groupColumns=[], unit=1s) =>
tables
|> derivative(nonNegative:true, unit:unit)
|> aggregateWindow(every: every, fn : (tables=<-, column) =>
tables
|> mean(column: column)
|> group(columns: groupColumns)
|> experimental.group(columns: ["_start", "_stop"], mode:"extend")
|> sum()
)
```
_**Used functions:**_
[aggregateWindow()](/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/aggregatewindow/)
[derivative()](/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/derivative/)
[experimental.group()](/v2.0/reference/flux/stdlib/experimental/group/)
[group()](/v2.0/reference/flux/stdlib/built-in/transformations/group/)
[mean()](/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/mean/)
[sum()](/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/sum/)