updated aggregate functions to use single column

pull/132/head
Scott Anderson 2019-04-08 15:07:20 -06:00
parent b9fa15cc77
commit a680327f2c
14 changed files with 97 additions and 96 deletions

View File

@ -17,13 +17,12 @@ Flux's built-in aggregate functions take values from an input table and aggregat
The output table contains is a single row with the aggregated value.
Aggregate operations output a table for every input table they receive.
A list of columns to aggregate must be provided to the operation.
The aggregate function is applied to each column in isolation.
A column to aggregate must be provided to the operation.
Any output table will have the following properties:
- It always contains a single record.
- It will have the same group key as the input table.
- It will contain a column for each provided aggregate column.
- It will contain a column for the provided aggregate column.
The column label will be the same as the input table.
The type of the column depends on the specific aggregate operation.
The value of the column will be `null` if the input table is empty or the input column has only `null` values.

View File

@ -18,7 +18,7 @@ _**Function type:** Aggregate_
aggregateWindow(
every: 1m,
fn: mean,
columns: ["_value"],
column: "_value",
timeColumn: "_stop",
timeDst: "_time",
createEmpty: true
@ -26,7 +26,7 @@ aggregateWindow(
```
As data is windowed into separate tables and aggregated, the `_time` column is dropped from each group key.
This helper copies the timestamp from a remaining column into the `_time` column.
This function copies the timestamp from a remaining column into the `_time` column.
View the [function definition](#function-definition).
## Parameters
@ -41,11 +41,11 @@ The aggregate function used in the operation.
_**Data type:** Function_
### columns
List of columns on which to operate.
Defaults to `["_value"]`.
### column
The column on which to operate.
Defaults to `"_value"`.
_**Data type:** Array of strings_
_**Data type:** String_
### timeColumn
The time column from which time is copied for the aggregate record.
@ -93,16 +93,16 @@ from(bucket: "telegraf/autogen")
r._field == "used_percent")
|> aggregateWindow(
every: 5m,
fn: (columns, tables=<-) => tables |> quantile(q: 0.99, columns:columns)
fn: (column, tables=<-) => tables |> quantile(q: 0.99, column:column)
)
```
## Function definition
```js
aggregateWindow = (every, fn, columns=["_value"], timeColumn="_stop", timeDst="_time", tables=<-) =>
aggregateWindow = (every, fn, column="_value", timeColumn="_stop", timeDst="_time", tables=<-) =>
tables
|> window(every:every)
|> fn(columns:columns)
|> fn(column:column)
|> duplicate(column:timeColumn, as:timeDst)
|> window(every:inf, timeColumn:timeDst)
```

View File

@ -1,6 +1,6 @@
---
title: count() function
description: The `count()` function outputs the number of non-null records in each aggregated column.
description: The `count()` function outputs the number of non-null records in a column.
aliases:
- /v2.0/reference/flux/functions/transformations/aggregates/count
menu:
@ -10,23 +10,23 @@ menu:
weight: 501
---
The `count()` function outputs the number of records in each aggregated column.
The `count()` function outputs the number of records in a column.
It counts both null and non-null records.
_**Function type:** Aggregate_
_**Output data type:** Integer_
```js
count(columns: ["_value"])
count(column: "_value")
```
## Parameters
### columns
A list of columns on which to operate
Defaults to `["_value"]`.
### column
The column on which to operate.
Defaults to `"_value"`.
_**Data type: Array of strings**_
_**Data type: String**_
## Examples
```js
@ -38,7 +38,7 @@ from(bucket: "telegraf/autogen")
```js
from(bucket: "telegraf/autogen")
|> range(start: -5m)
|> count(columns: ["_value"])
|> count(column: "_value")
```
<hr style="margin-top:4rem"/>

View File

@ -12,7 +12,7 @@ weight: 501
The `derivative()` function computes the rate of change per [`unit`](#unit) of time between subsequent non-null records.
It assumes rows are ordered by the `_time` column.
The output table schema will be the same as the input table.
The output table schema is the same as the input table.
_**Function type:** Aggregate_
_**Output data type:** Float_
@ -21,7 +21,7 @@ _**Output data type:** Float_
derivative(
unit: 1s,
nonNegative: false,
columns: ["_value"],
column: "_value",
timeSrc: "_time"
)
```
@ -40,11 +40,11 @@ When set to `true`, if a value is less than the previous value, it is assumed th
_**Data type:** Boolean_
### columns
A list of columns on which to compute the derivative.
Defaults to `["_value"]`.
### column
The column on which to compute the derivative.
Defaults to `"_value"`.
_**Data type:** Array of strings_
_**Data type:** String_
### timeSrc
The column containing time values.

View File

@ -11,13 +11,13 @@ weight: 501
---
The `difference()` function computes the difference between subsequent records.
Every user-specified column of numeric type is subtracted while others are kept intact.
The user-specified column of numeric type is subtracted while others are kept intact.
_**Function type:** Aggregate_
_**Output data type:** Float_
```js
difference(nonNegative: false, columns: ["_value"])
difference(nonNegative: false, column: "_value")
```
## Parameters
@ -28,11 +28,11 @@ When set to `true`, if a value is less than the previous value, it is assumed th
_**Data type:** Boolean_
### columns
A list of columns on which to compute the difference.
Defaults to `["_value"]`.
### column
The column on which to compute the difference.
Defaults to `"_value"`.
_**Data type:** Array of strings_
_**Data type:** String_
## Subtraction rules for numeric types
- The difference between two non-null values is their algebraic difference;
@ -58,37 +58,37 @@ from(bucket: "telegraf/autogen")
### Example data transformation
###### Input table
| _time | A | B | C | tag |
|:-----:|:----:|:----:|:----:|:---:|
| 0001 | null | 1 | 2 | tv |
| 0002 | 6 | 2 | null | tv |
| 0003 | 4 | 2 | 4 | tv |
| 0004 | 10 | 10 | 2 | tv |
| 0005 | null | null | 1 | tv |
| _time | _value | tag |
|:-----:|:------:|:---:|
| 0001 | null | tv |
| 0002 | 6 | tv |
| 0003 | 4 | tv |
| 0004 | 10 | tv |
| 0005 | null | tv |
#### With nonNegative set to false
```js
|> difference(nonNegative: false)
```
###### Output table
| _time | A | B | C | tag |
|:-----:|:----:|:----:|:----:|:---:|
| 0002 | null | 1 | null | tv |
| 0003 | -2 | 0 | 2 | tv |
| 0004 | 6 | 8 | -2 | tv |
| 0005 | null | null | -1 | tv |
| _time | _value | tag |
|:-----:|:------:|:---:|
| 0002 | null | tv |
| 0003 | -2 | tv |
| 0004 | 6 | tv |
| 0005 | null | tv |
#### With nonNegative set to true
```js
|> difference(nonNegative: true):
```
###### Output table
| _time | A | B | C | tag |
|:-----:|:----:|:----:|:----:|:---:|
| 0002 | null | 1 | null | tv |
| 0003 | null | 0 | 2 | tv |
| 0004 | 6 | 8 | null | tv |
| 0005 | null | null | null | tv |
| _time | _value | tag |
|:-----:|:------:|:---:|
| 0002 | null | tv |
| 0003 | null | tv |
| 0004 | 6 | tv |
| 0005 | null | tv |
<hr style="margin-top:4rem"/>

View File

@ -1,6 +1,8 @@
---
title: histogramQuantile() function
description: The `histogramQuantile()` function approximates a quantile given a histogram that approximates the cumulative distribution of the dataset.
description: >
The `histogramQuantile()` function approximates a quantile given a histogram
that approximates the cumulative distribution of the dataset.
aliases:
- /v2.0/reference/flux/functions/transformations/aggregates/histogramquantile
menu:

View File

@ -20,16 +20,16 @@ _**Function type:** Aggregate_
_**Output data type:** Float_
```js
increase(columns: ["_values"])
increase(column: "_values")
```
## Parameters
### columns
The list of columns for which the increase is calculated.
Defaults to `["_value"]`.
### column
The column for which the increase is calculated.
Defaults to `"_value"`.
_**Data type:** Array of strings_
_**Data type:** Strings_
## Examples
```js
@ -61,8 +61,8 @@ Given the following input table:
## Function definition
```js
increase = (tables=<-, columns=["_value"]) =>
increase = (tables=<-, column="_value") =>
tables
|> difference(nonNegative: true, columns:columns)
|> difference(nonNegative: true, column:column)
|> cumulativeSum()
```

View File

@ -17,7 +17,7 @@ _**Function type:** Aggregate_
_**Output data type:** Float_
```js
integral(unit: 10s, columns: ["_value"])
integral(unit: 10s, column: "_value")
```
## Parameters
@ -27,11 +27,11 @@ The time duration used when computing the integral.
_**Data type:** Duration_
### columns
A list of columns on which to operate.
Defaults to `["_value"]`.
### column
The column on which to operate.
Defaults to `"_value"`.
_**Data type:** Array of strings_
_**Data type:** String_
## Examples
```js

View File

@ -16,16 +16,16 @@ _**Function type:** Aggregate_
_**Output data type:** Float_
```js
mean(columns: ["_value"])
mean(column: "_value")
```
## Parameters
### columns
A list of columns on which to compute the mean.
Defaults to `["_value"]`.
### column
The column on which to compute the mean.
Defaults to `"_value"`.
_**Data type:** Array of strings_
_**Data type:** String_
## Examples
```js

View File

@ -20,7 +20,7 @@ _**Output data type:** Float or Object_
```js
quantile(
columns: ["_value"],
column: "_value",
q: 0.99,
method: "estimate_tdigest",
compression: 1000.0
@ -35,11 +35,11 @@ value that represents the specified quantile.
## Parameters
### columns
A list of columns on which to compute the quantile.
Defaults to `["_value"]`.
### column
The column on which to compute the quantile.
Defaults to `"_value"`.
_**Data type:** Array of strings_
_**Data type:** String_
### q
A value between 0 and 1 indicating the desired quantile.

View File

@ -16,15 +16,15 @@ _**Function type:** Aggregate_
_**Output data type:** Float_
```js
skew(columns: ["_value"])
skew(column: "_value")
```
## Parameters
### columns
Specifies a list of columns on which to operate. Defaults to `["_value"]`.
### column
The column on which to operate. Defaults to `"_value"`.
_**Data type:** Array of strings_
_**Data type:** String_
## Examples
```js

View File

@ -1,6 +1,6 @@
---
title: spread() function
description: The `spread()` function outputs the difference between the minimum and maximum values in each specified column.
description: The `spread()` function outputs the difference between the minimum and maximum values in a specified column.
aliases:
- /v2.0/reference/flux/functions/transformations/aggregates/spread
menu:
@ -10,12 +10,12 @@ menu:
weight: 501
---
The `spread()` function outputs the difference between the minimum and maximum values in each specified column.
The `spread()` function outputs the difference between the minimum and maximum values in a specified column.
Only `uint`, `int`, and `float` column types can be used.
The type of the output column depends on the type of input column:
- For input columns with type `uint` or `int`, the output is an `int`
- For input columns with type `float` the output is a float.
- For columns with type `uint` or `int`, the output is an `int`
- For columns with type `float`, the output is a float.
_**Function type:** Aggregate_
_**Output data type:** Integer or Float (inherited from input column type)_

View File

@ -1,6 +1,6 @@
---
title: stddev() function
description: The `stddev()` function computes the standard deviation of non-null records in specified columns.
description: The `stddev()` function computes the standard deviation of non-null records in a specified column.
aliases:
- /v2.0/reference/flux/functions/transformations/aggregates/stddev
menu:
@ -10,22 +10,22 @@ menu:
weight: 501
---
The `stddev()` function computes the standard deviation of non-null records in specified columns.
The `stddev()` function computes the standard deviation of non-null records in a specified column.
_**Function type:** Aggregate_
_**Output data type:** Float_
```js
stddev(columns: ["_value"])
stddev(column: "_value")
```
## Parameters
### columns
Specifies a list of columns on which to operate.
Defaults to `["_value"]`.
### column
The column on which to operate.
Defaults to `"_value"`.
_**Data type:** Array of strings_
_**Data type:** String_
## Examples
```js

View File

@ -1,6 +1,6 @@
---
title: sum() function
description: The `sum()` function computes the sum of non-null records in specified columns.
description: The `sum()` function computes the sum of non-null records in a specified column.
aliases:
- /v2.0/reference/flux/functions/transformations/aggregates/sum
menu:
@ -10,22 +10,22 @@ menu:
weight: 501
---
The `sum()` function computes the sum of non-null records in specified columns.
The `sum()` function computes the sum of non-null records in a specified column.
_**Function type:** Aggregate_
_**Output data type:** Integer, UInteger, or Float (inherited from column type)_
```js
sum(columns: ["_value"])
sum(column: "_value")
```
## Parameters
### columns
Specifies a list of columns on which to operate.
Defaults to `["_value"]`.
### column
The column on which to operate.
Defaults to `"_value"`.
_**Data type:** Array of strings_
_**Data type:** String_
## Examples
```js