added flux function docs
parent
8e254a3b43
commit
8025dd561e
|
@ -51,7 +51,7 @@ are unique to each row.
|
|||
|
||||
## Tools for working with Flux
|
||||
|
||||
You have multiple [options for writing and running Flux queries](/flux/v0.12/guides/executing-queries),
|
||||
You have multiple [options for writing and running Flux queries](/v2.0/reference/flux/guides/executing-queries),
|
||||
but as you're getting started, we recommend using the following:
|
||||
|
||||
### 1. Data Explorer
|
||||
|
|
|
@ -17,8 +17,8 @@ Every Flux query needs the following:
|
|||
|
||||
|
||||
## 1. Define your data source
|
||||
Flux's [`from()`](#) function defines an InfluxDB data source.
|
||||
It requires a [`bucket`](#) parameter.
|
||||
Flux's [`from()`](/v2.0/reference/flux/functions/inputs/from) function defines an InfluxDB data source.
|
||||
It requires a [`bucket`](/v2.0/reference/flux/functions/inputs/from#bucket) parameter.
|
||||
The following examples use `example-bucket` as the bucket name.
|
||||
|
||||
```js
|
||||
|
@ -30,11 +30,11 @@ Flux requires a time range when querying time series data.
|
|||
"Unbounded" queries are very resource-intensive and as a protective measure,
|
||||
Flux will not query the database without a specified range.
|
||||
|
||||
Use the pipe-forward operator (`|>`) to pipe data from your data source into the [`range()`](/flux/v0.12/functions/transformations/range)
|
||||
Use the pipe-forward operator (`|>`) to pipe data from your data source into the [`range()`](/v2.0/reference/flux/functions/transformations/range)
|
||||
function, which specifies a time range for your query.
|
||||
It accepts two properties: `start` and `stop`.
|
||||
Ranges can be **relative** using negative [durations](/flux/v0.12/language/lexical-elements#duration-literals)
|
||||
or **absolute** using [timestamps](/flux/v0.12/language/lexical-elements#date-and-time-literals).
|
||||
Ranges can be **relative** using negative [durations](/v2.0/reference/flux/language/lexical-elements#duration-literals)
|
||||
or **absolute** using [timestamps](/v2.0/reference/flux/language/lexical-elements#date-and-time-literals).
|
||||
|
||||
###### Example relative time ranges
|
||||
```js
|
||||
|
|
|
@ -183,7 +183,7 @@ topN = (tables=<-, n) => tables |> sort(desc: true) |> limit(n: n)
|
|||
{{% /code-tab-content %}}
|
||||
{{< /code-tabs-wrapper >}}
|
||||
|
||||
_More information about creating custom functions is available in the [Custom functions](/flux/v0.12/functions/custom-functions) documentation._
|
||||
_More information about creating custom functions is available in the [Custom functions](/v2.0/reference/flux/functions/custom-functions) documentation._
|
||||
|
||||
Using the `cpuUsageUser` data stream variable defined above, find the top five data
|
||||
points with the custom `topN` function and yield the results.
|
||||
|
|
|
@ -12,7 +12,7 @@ When [querying data from InfluxDB](/v2.0/query-data/flux/get-started/query-influ
|
|||
you often need to transform that data in some way.
|
||||
Common examples are aggregating data into averages, downsampling data, etc.
|
||||
|
||||
This guide demonstrates using [Flux functions](/flux/v0.12/functions) to transform your data.
|
||||
This guide demonstrates using [Flux functions](/v2.0/reference/flux/functions) to transform your data.
|
||||
It walks through creating a Flux script that partitions data into windows of time,
|
||||
averages the `_value`s in each window, and outputs the averages as a new table.
|
||||
|
||||
|
@ -34,14 +34,14 @@ from(bucket:"example-bucket")
|
|||
|
||||
## Flux functions
|
||||
Flux provides a number of functions that perform specific operations, transformations, and tasks.
|
||||
You can also [create custom functions](/flux/v0.12/functions/custom-functions) in your Flux queries.
|
||||
_Functions are covered in detail in the [Flux functions](/flux/v0.12/functions) documentation._
|
||||
You can also [create custom functions](/v2.0/reference/flux/functions/custom-functions) in your Flux queries.
|
||||
_Functions are covered in detail in the [Flux functions](/v2.0/reference/flux/functions) documentation._
|
||||
|
||||
A common type of function used when transforming data queried from InfluxDB is an aggregate function.
|
||||
Aggregate functions take a set of `_value`s in a table, aggregate them, and transform
|
||||
them into a new value.
|
||||
|
||||
This example uses the [`mean()` function](/flux/v0.12/functions/transformations/aggregates/mean)
|
||||
This example uses the [`mean()` function](/v2.0/reference/flux/functions/transformations/aggregates/mean)
|
||||
to average values within each time window.
|
||||
|
||||
{{% note %}}
|
||||
|
@ -51,7 +51,7 @@ It's just good to understand the steps in the process.
|
|||
{{% /note %}}
|
||||
|
||||
## Window your data
|
||||
Flux's [`window()` function](/flux/v0.12/functions/transformations/window) partitions records based on a time value.
|
||||
Flux's [`window()` function](/v2.0/reference/flux/functions/transformations/window) partitions records based on a time value.
|
||||
Use the `every` parameter to define a duration of each window.
|
||||
|
||||
For this example, window data in five minute intervals (`5m`).
|
||||
|
@ -74,7 +74,7 @@ When visualized, each table is assigned a unique color.
|
|||
|
||||
## Aggregate windowed data
|
||||
Flux aggregate functions take the `_value`s in each table and aggregate them in some way.
|
||||
Use the [`mean()` function](/flux/v0.12/functions/transformations/aggregates/mean) to average the `_value`s of each table.
|
||||
Use the [`mean()` function](/v2.0/reference/flux/functions/transformations/aggregates/mean) to average the `_value`s of each table.
|
||||
|
||||
```js
|
||||
from(bucket:"example-bucket")
|
||||
|
@ -100,7 +100,7 @@ Aggregate functions don't infer what time should be used for the aggregate value
|
|||
Therefore the `_time` column is dropped.
|
||||
|
||||
A `_time` column is required in the [next operation](#unwindow-aggregate-tables).
|
||||
To add one, use the [`duplicate()` function](/flux/v0.12/functions/transformations/duplicate)
|
||||
To add one, use the [`duplicate()` function](/v2.0/reference/flux/functions/transformations/duplicate)
|
||||
to duplicate the `_stop` column as the `_time` column for each windowed table.
|
||||
|
||||
```js
|
||||
|
@ -145,7 +145,7 @@ process helps to understand how data changes "shape" as it is passed through eac
|
|||
|
||||
Flux provides (and allows you to create) "helper" functions that abstract many of these steps.
|
||||
The same operation performed in this guide can be accomplished using the
|
||||
[`aggregateWindow()` function](/flux/v0.12/functions/transformations/aggregates/aggregatewindow).
|
||||
[`aggregateWindow()` function](/v2.0/reference/flux/functions/transformations/aggregates/aggregatewindow).
|
||||
|
||||
```js
|
||||
from(bucket:"example-bucket")
|
||||
|
@ -166,7 +166,7 @@ and your own custom functions, but this is a good introduction into the basic sy
|
|||
---
|
||||
|
||||
_For a deeper dive into windowing and aggregating data with example data output for each transformation,
|
||||
view the [Windowing and aggregating data](/flux/v0.12/guides/windowing-aggregating) guide._
|
||||
view the [Windowing and aggregating data](/v2.0/reference/flux/guides/windowing-aggregating) guide._
|
||||
|
||||
---
|
||||
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
---
|
||||
title: Flux functions
|
||||
description: Flux functions allows you to retrieve, transform, process, and output data easily.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: Flux functions
|
||||
parent: Flux query language
|
||||
weight: 4
|
||||
---
|
||||
|
||||
Flux's functional syntax allows you to retrieve, transform, process, and output data easily.
|
||||
There is a large library of built-in functions, but you can also create your own
|
||||
custom functions to perform operations that suit your needs.
|
||||
|
||||
## [Input functions](/v2.0/reference/flux/functions/inputs)
|
||||
Input functions define or display information about data sources.
|
||||
|
||||
## [Output functions](/v2.0/reference/flux/functions/outputs)
|
||||
Output functions yield results or send data to a specified output.
|
||||
|
||||
## [Transformation functions](/v2.0/reference/flux/functions/transformations)
|
||||
Transformation functions transform or shape your data in specific ways.
|
||||
|
||||
## [Miscellaneous functions](/v2.0/reference/flux/functions/misc)
|
||||
Functions that serve miscellaneous purposes when writing Flux scripts.
|
||||
|
||||
## [Custom functions](/v2.0/reference/flux/functions/custom-functions)
|
||||
Flux's functional syntax allows for custom functions.
|
||||
This guide walks through the basics of creating your own function.
|
|
@ -0,0 +1,133 @@
|
|||
---
|
||||
title: Create custom Flux functions
|
||||
description: Create your own custom Flux functions to transform and manipulate data.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: Custom functions
|
||||
parent: Flux functions
|
||||
weight: 6
|
||||
---
|
||||
|
||||
Flux's functional syntax allows for custom functions.
|
||||
This guide walks through the basics of creating your own function.
|
||||
|
||||
## Function definition structure
|
||||
The basic structure for defining functions in Flux is as follows:
|
||||
|
||||
```js
|
||||
// Basic function definition structure
|
||||
functionName = (functionParameters) => functionOperations
|
||||
```
|
||||
|
||||
##### `functionName`
|
||||
The name used to call the function in your Flux script.
|
||||
|
||||
##### `functionParameters`
|
||||
A comma-separated list of parameters passed into the function and used in its operations.
|
||||
[Parameter defaults](#define-parameter-defaults) can be defined for each.
|
||||
|
||||
##### `functionOperations`
|
||||
Operations and functions that manipulate the input into the desired output.
|
||||
|
||||
#### Basic function examples
|
||||
|
||||
###### Example square function
|
||||
```js
|
||||
// Function definition
|
||||
square = (n) => n * n
|
||||
|
||||
// Function usage
|
||||
> square(n:3)
|
||||
9
|
||||
```
|
||||
|
||||
###### Example multiply function
|
||||
```js
|
||||
// Function definition
|
||||
multiply = (x, y) => x * y
|
||||
|
||||
// Function usage
|
||||
> multiply(x:2, y:15)
|
||||
30
|
||||
```
|
||||
|
||||
## Functions that manipulate pipe-forwarded data
|
||||
Most Flux functions manipulate data pipe-forwarded into the function.
|
||||
In order for a custom function to process pipe-forwarded data, one of the function
|
||||
parameters must capture the input tables using the `<-` pipe-receive expression.
|
||||
|
||||
In the example below, the `tables` parameter is assigned to the `<-` expression,
|
||||
which represents all data pipe-forwarded into the function.
|
||||
`tables` is then pipe-forwarded into other operations in the function definition.
|
||||
|
||||
```js
|
||||
functionName = (tables=<-) => tables |> functionOperations
|
||||
```
|
||||
|
||||
#### Pipe-forwardable function example
|
||||
|
||||
###### Multiply row values by x
|
||||
The example below defines a `multByX` function that multiplies the `_value` column
|
||||
of each row in the input table by the `x` parameter.
|
||||
It uses the [`map()` function](/v2.0/reference/flux/functions/transformations/map) to modify each `_value`.
|
||||
|
||||
```js
|
||||
// Function definition
|
||||
multByX = (tables=<-, x) =>
|
||||
tables
|
||||
|> map(fn: (r) => r._value * x)
|
||||
|
||||
// Function usage
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: -1m)
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "mem" and
|
||||
r._field == "used_percent"
|
||||
)
|
||||
|> multByX(x:2.0)
|
||||
```
|
||||
|
||||
## Define parameter defaults
|
||||
To define parameters with default values, use the `=` assignment operator to assign
|
||||
a default in your function definition:
|
||||
|
||||
```js
|
||||
functionName = (param1=defaultValue1, param2=defaultValue2) => functionOperation
|
||||
```
|
||||
|
||||
Defaults are overridden by explicitly defining the parameter in the function call.
|
||||
|
||||
#### Example functions with defaults
|
||||
|
||||
###### Get the winner or the "winner"
|
||||
The example below defines a `getWinner` function that returns the record with the highest
|
||||
or lowest `_value` (winner versus "winner") depending on the `noSarcasm` parameter which defaults to `true`.
|
||||
It uses the [`sort()` function](/v2.0/reference/flux/functions/transformations/sort) to sort records in either descending or ascending order.
|
||||
It then uses the [`limit()` function](/v2.0/reference/flux/functions/transformations/limit) to return the first record from the sorted table.
|
||||
|
||||
```js
|
||||
// Function definition
|
||||
getWinner = (tables=<-, noSarcasm:true) =>
|
||||
tables
|
||||
|> sort(desc: noSarcasm)
|
||||
|> limit(n:1)
|
||||
|
||||
// Function usage
|
||||
// Get the winner
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: -1m)
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "mem" and
|
||||
r._field == "used_percent"
|
||||
)
|
||||
|> getWinner()
|
||||
|
||||
// Get the "winner"
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: -1m)
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "mem" and
|
||||
r._field == "used_percent"
|
||||
)
|
||||
|> getWinner(noSarcasm: false)
|
||||
```
|
|
@ -0,0 +1,14 @@
|
|||
---
|
||||
title: Flux input functions
|
||||
description: Flux input functions define sources of data or or display information about data sources.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
parent: Flux functions
|
||||
name: Inputs
|
||||
weight: 1
|
||||
---
|
||||
|
||||
Flux input functions define sources of data or display information about data sources.
|
||||
The following input functions are available:
|
||||
|
||||
{{< function-list category="Inputs" menu="v2_0_ref" >}}
|
|
@ -0,0 +1,22 @@
|
|||
---
|
||||
title: buckets() function
|
||||
description: The buckets() function returns a list of buckets in the organization.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: buckets
|
||||
parent: Inputs
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `buckets()` function returns a list of buckets in the organization.
|
||||
|
||||
_**Function type:** Input_
|
||||
|
||||
```js
|
||||
buckets()
|
||||
```
|
||||
|
||||
<hr style="margin-top:4rem"/>
|
||||
|
||||
##### Related InfluxQL functions and statements:
|
||||
[SHOW DATABASES](https://docs.influxdata.com/influxdb/latest/query_language/schema_exploration/#show-databases)
|
|
@ -0,0 +1,50 @@
|
|||
---
|
||||
title: from() function
|
||||
description: The from() function retrieves data from an InfluxDB data source.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: from
|
||||
parent: Inputs
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `from()` function retrieves data from an InfluxDB data source.
|
||||
It returns a stream of tables from the specified [bucket](#parameters).
|
||||
Each unique series is contained within its own table.
|
||||
Each record in the table represents a single point in the series.
|
||||
|
||||
_**Function type:** Input_
|
||||
_**Output data type:** Object_
|
||||
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|
||||
// OR
|
||||
|
||||
from(bucketID: "0261d8287f4d6000")
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### bucket
|
||||
The name of the bucket to query.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
### bucketID
|
||||
The string-encoded ID of the bucket to query.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
```
|
||||
```js
|
||||
from(bucketID: "0261d8287f4d6000")
|
||||
```
|
||||
|
||||
<hr style="margin-top:4rem"/>
|
||||
|
||||
##### Related InfluxQL functions and statements:
|
||||
[FROM](https://docs.influxdata.com/influxdb/latest/query_language/data_exploration/#from-clause)
|
|
@ -0,0 +1,64 @@
|
|||
---
|
||||
title: fromCSV() function
|
||||
description: The fromCSV() function retrieves data from a CSV data source.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: fromCSV
|
||||
parent: Inputs
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `fromCSV()` function retrieves data from a comma-separated value (CSV) data source.
|
||||
It returns a stream of tables.
|
||||
Each unique series is contained within its own table.
|
||||
Each record in the table represents a single point in the series.
|
||||
|
||||
_**Function type:** Input_
|
||||
_**Output data type:** Object_
|
||||
|
||||
```js
|
||||
from(file: "/path/to/data-file.csv")
|
||||
|
||||
// OR
|
||||
|
||||
from(csv: csvData)
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### file
|
||||
The file path of the CSV file to query.
|
||||
The path can be absolute or relative.
|
||||
If relative, it is relative to the working directory of the `influxd` process.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
### csv
|
||||
Raw CSV-formatted text.
|
||||
|
||||
{{% note %}}
|
||||
CSV data must be in the CSV format produced by the Flux HTTP response standard.
|
||||
See the [Flux technical specification](https://github.com/influxdata/flux/blob/master/docs/SPEC.md#csv)
|
||||
for information about this format.
|
||||
{{% /note %}}
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
## Examples
|
||||
|
||||
### Query CSV data from a file
|
||||
```js
|
||||
from(file: "/path/to/data-file.csv")
|
||||
```
|
||||
|
||||
### Query raw CSV-formatted text
|
||||
```js
|
||||
csvData = "
|
||||
result,table,_start,_stop,_time,region,host,_value
|
||||
mean,0,2018-05-08T20:50:00Z,2018-05-08T20:51:00Z,2018-05-08T20:50:00Z,east,A,15.43
|
||||
mean,0,2018-05-08T20:50:00Z,2018-05-08T20:51:00Z,2018-05-08T20:50:20Z,east,B,59.25
|
||||
mean,0,2018-05-08T20:50:00Z,2018-05-08T20:51:00Z,2018-05-08T20:50:40Z,east,C,52.62
|
||||
"
|
||||
|
||||
from(csv: csvData)
|
||||
```
|
|
@ -0,0 +1,15 @@
|
|||
---
|
||||
title: Flux miscellaneous functions
|
||||
description: Flux provides miscellaneous functions that serve purposes other than retrieving, transforming, or outputting data.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
parent: Flux functions
|
||||
name: Miscellaneous
|
||||
weight: 5
|
||||
---
|
||||
|
||||
Flux functions primarily retrieve, shape and transform, then output data, however
|
||||
there are functions available that serve other purposes.
|
||||
The following functions are are available but don't fit within other function categories:
|
||||
|
||||
{{< function-list category="Miscellaneous" menu="v2_0_ref" >}}
|
|
@ -0,0 +1,154 @@
|
|||
---
|
||||
title: intervals() function
|
||||
description: The intervals() function generates a set of time intervals over a range of time.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: intervals
|
||||
parent: Miscellaneous
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `intervals()` function generates a set of time intervals over a range of time.
|
||||
|
||||
An interval is an object with `start` and `stop` properties that correspond to the inclusive start and exclusive stop times of the time interval.
|
||||
The return value of intervals is another function that accepts start and stop time parameters and returns an interval generator.
|
||||
The generator is then used to produce the set of intervals.
|
||||
The set of intervals includes all intervals that intersect with the initial range of time.
|
||||
|
||||
{{% note %}}
|
||||
The `intervals()` function is designed to be used with the intervals parameter of the [`window()` function](/v2.0/reference/flux/functions/transformations/window).
|
||||
{{% /note %}}
|
||||
|
||||
_**Function type:** Miscellaneous_
|
||||
_**Output data type:** Object_
|
||||
|
||||
```js
|
||||
intervals()
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### every
|
||||
The duration between starts of each of the intervals.
|
||||
The Nth interval start time is the initial start time plus the offset plus an Nth multiple of the every parameter.
|
||||
Defaults to the value of the `period` duration.
|
||||
|
||||
_**Data type:** Duration_
|
||||
|
||||
### period
|
||||
The length of each interval.
|
||||
Each interval's stop time is equal to the interval start time plus the period duration.
|
||||
It can be negative, indicating the start and stop boundaries are reversed.
|
||||
Defaults to the value of the `every` duration.
|
||||
|
||||
_**Data type:** Duration_
|
||||
|
||||
### offset
|
||||
The offset duration relative to the location offset.
|
||||
It can be negative, indicating that the offset goes backwards in time.
|
||||
Defaults to `0h`.
|
||||
|
||||
_**Data type:** Duration_
|
||||
|
||||
### filter
|
||||
A function that accepts an interval object and returns a boolean value.
|
||||
Each potential interval is passed to the filter function.
|
||||
When the function returns false, that interval is excluded from the set of intervals.
|
||||
Defaults to include all intervals.
|
||||
|
||||
_**Data type:** Function_
|
||||
|
||||
## Examples
|
||||
|
||||
##### Basic intervals
|
||||
```js
|
||||
// 1 hour intervals
|
||||
intervals(every:1h)
|
||||
|
||||
// 2 hour long intervals every 1 hour
|
||||
intervals(every:1h, period:2h)
|
||||
|
||||
// 2 hour long intervals every 1 hour starting at 30m past the hour
|
||||
intervals(every:1h, period:2h, offset:30m)
|
||||
|
||||
// 1 week intervals starting on Monday (by default weeks start on Sunday)
|
||||
intervals(every:1w, offset:1d)
|
||||
|
||||
// the hour from 11PM - 12AM every night
|
||||
intervals(every:1d, period:-1h)
|
||||
|
||||
// the last day of each month
|
||||
intervals(every:1mo, period:-1d)
|
||||
```
|
||||
|
||||
##### Using a predicate
|
||||
```js
|
||||
// 1 day intervals excluding weekends
|
||||
intervals(
|
||||
every:1d,
|
||||
filter: (interval) => !(weekday(time: interval.start) in [Sunday, Saturday]),
|
||||
)
|
||||
|
||||
// Work hours from 9AM - 5PM on work days.
|
||||
intervals(
|
||||
every:1d,
|
||||
period:8h,
|
||||
offset:9h,
|
||||
filter:(interval) => !(weekday(time: interval.start) in [Sunday, Saturday]),
|
||||
)
|
||||
```
|
||||
|
||||
##### Using known start and stop dates
|
||||
```js
|
||||
// Every hour for six hours on Sep 5th.
|
||||
intervals(every:1h)(start:2018-09-05T00:00:00-07:00, stop: 2018-09-05T06:00:00-07:00)
|
||||
|
||||
// Generates
|
||||
// [2018-09-05T00:00:00-07:00, 2018-09-05T01:00:00-07:00)
|
||||
// [2018-09-05T01:00:00-07:00, 2018-09-05T02:00:00-07:00)
|
||||
// [2018-09-05T02:00:00-07:00, 2018-09-05T03:00:00-07:00)
|
||||
// [2018-09-05T03:00:00-07:00, 2018-09-05T04:00:00-07:00)
|
||||
// [2018-09-05T04:00:00-07:00, 2018-09-05T05:00:00-07:00)
|
||||
// [2018-09-05T05:00:00-07:00, 2018-09-05T06:00:00-07:00)
|
||||
|
||||
// Every hour for six hours with 1h30m periods on Sep 5th
|
||||
intervals(every:1h, period:1h30m)(start:2018-09-05T00:00:00-07:00, stop: 2018-09-05T06:00:00-07:00)
|
||||
|
||||
// Generates
|
||||
// [2018-09-05T00:00:00-07:00, 2018-09-05T01:30:00-07:00)
|
||||
// [2018-09-05T01:00:00-07:00, 2018-09-05T02:30:00-07:00)
|
||||
// [2018-09-05T02:00:00-07:00, 2018-09-05T03:30:00-07:00)
|
||||
// [2018-09-05T03:00:00-07:00, 2018-09-05T04:30:00-07:00)
|
||||
// [2018-09-05T04:00:00-07:00, 2018-09-05T05:30:00-07:00)
|
||||
// [2018-09-05T05:00:00-07:00, 2018-09-05T06:30:00-07:00)
|
||||
|
||||
// Every hour for six hours using the previous hour on Sep 5th
|
||||
intervals(every:1h, period:-1h)(start:2018-09-05T12:00:00-07:00, stop: 2018-09-05T18:00:00-07:00)
|
||||
|
||||
// Generates
|
||||
// [2018-09-05T11:00:00-07:00, 2018-09-05T12:00:00-07:00)
|
||||
// [2018-09-05T12:00:00-07:00, 2018-09-05T13:00:00-07:00)
|
||||
// [2018-09-05T13:00:00-07:00, 2018-09-05T14:00:00-07:00)
|
||||
// [2018-09-05T14:00:00-07:00, 2018-09-05T15:00:00-07:00)
|
||||
// [2018-09-05T15:00:00-07:00, 2018-09-05T16:00:00-07:00)
|
||||
// [2018-09-05T16:00:00-07:00, 2018-09-05T17:00:00-07:00)
|
||||
// [2018-09-05T17:00:00-07:00, 2018-09-05T18:00:00-07:00)
|
||||
|
||||
// Every month for 4 months starting on Jan 1st
|
||||
intervals(every:1mo)(start:2018-01-01, stop: 2018-05-01)
|
||||
|
||||
// Generates
|
||||
// [2018-01-01, 2018-02-01)
|
||||
// [2018-02-01, 2018-03-01)
|
||||
// [2018-03-01, 2018-04-01)
|
||||
// [2018-04-01, 2018-05-01)
|
||||
|
||||
// Every month for 4 months starting on Jan 15th
|
||||
intervals(every:1mo)(start:2018-01-15, stop: 2018-05-15)
|
||||
|
||||
// Generates
|
||||
// [2018-01-15, 2018-02-15)
|
||||
// [2018-02-15, 2018-03-15)
|
||||
// [2018-03-15, 2018-04-15)
|
||||
// [2018-04-15, 2018-05-15)
|
||||
```
|
|
@ -0,0 +1,51 @@
|
|||
---
|
||||
title: linearBins() function
|
||||
description: The linearBins() function generates a list of linearly separated floats.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: linearBins
|
||||
parent: Miscellaneous
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `linearBins()` function generates a list of linearly separated floats.
|
||||
It is a helper function meant to generate bin bounds for the
|
||||
[`histogram()` function](/v2.0/reference/flux/functions/transformations/histogram).
|
||||
|
||||
_**Function type:** Miscellaneous_
|
||||
_**Output data type:** Array of floats_
|
||||
|
||||
```js
|
||||
linearBins(start: 0.0, width: 5.0, count: 20, infinity: true)
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### start
|
||||
The first value in the returned list.
|
||||
|
||||
_**Data type:** Float_
|
||||
|
||||
### width
|
||||
The distance between subsequent bin values.
|
||||
|
||||
_**Data type:** Float_
|
||||
|
||||
### count
|
||||
The number of bins to create.
|
||||
|
||||
_**Data type:** Integer_
|
||||
|
||||
### infinity
|
||||
When `true`, adds an additional bin with a value of positive infinity.
|
||||
Defaults to `true`.
|
||||
|
||||
_**Data type:** Boolean_
|
||||
|
||||
## Examples
|
||||
|
||||
```js
|
||||
linearBins(start: 0.0, width: 10.0, count: 10)
|
||||
|
||||
// Generated list: [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, +Inf]
|
||||
```
|
|
@ -0,0 +1,50 @@
|
|||
---
|
||||
title: logarithmicBins() function
|
||||
description: The logarithmicBins() function generates a list of exponentially separated floats.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: logarithmicBins
|
||||
parent: Miscellaneous
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `logarithmicBins()` function generates a list of exponentially separated floats.
|
||||
It is a helper function meant to generate bin bounds for the
|
||||
[`histogram()` function](/v2.0/reference/flux/functions/transformations/histogram).
|
||||
|
||||
_**Function type:** Miscellaneous_
|
||||
_**Output data type:** Array of floats_
|
||||
|
||||
```js
|
||||
logarithmicBins(start:1.0, factor: 2.0, count: 10, infinity: true)
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### start
|
||||
The first value in the returned bin list.
|
||||
|
||||
_**Data type:** Float_
|
||||
|
||||
### factor
|
||||
The multiplier applied to each subsequent bin.
|
||||
|
||||
_**Data type:** Float_
|
||||
|
||||
### count
|
||||
The number of bins to create.
|
||||
|
||||
_**Data type:** Integer_
|
||||
|
||||
### infinity
|
||||
When `true`, adds an additional bin with a value of positive infinity.
|
||||
Defaults to `true`.
|
||||
|
||||
_**Data type:** Boolean_
|
||||
|
||||
## Examples
|
||||
```js
|
||||
logarithmicBins(start: 1.0, factor: 2.0, count: 10, infinty: true)
|
||||
|
||||
// Generated list: [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, +Inf]
|
||||
```
|
|
@ -0,0 +1,23 @@
|
|||
---
|
||||
title: systemTime() function
|
||||
description: The systemTime() function returns the current system time.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: systemTime
|
||||
parent: Miscellaneous
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `systemTime()` function returns the current system time.
|
||||
|
||||
_**Function type:** Date/Time_
|
||||
_**Output data type:** Timestamp_
|
||||
|
||||
```js
|
||||
systemTime()
|
||||
```
|
||||
|
||||
## Examples
|
||||
```js
|
||||
offsetTime = (offset) => systemTime() |> shift(shift: offset)
|
||||
```
|
|
@ -0,0 +1,14 @@
|
|||
---
|
||||
title: Flux output functions
|
||||
description: Flux output functions yield results or send data to a specified output destination.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
parent: Flux functions
|
||||
name: Outputs
|
||||
weight: 2
|
||||
---
|
||||
|
||||
Flux output functions yield results or send data to a specified output destination.
|
||||
The following output functions are are available:
|
||||
|
||||
{{< function-list category="Outputs" menu="v2_0_ref" >}}
|
|
@ -0,0 +1,158 @@
|
|||
---
|
||||
title: to() function
|
||||
description: The to() function writes data to an InfluxDB v2.0 bucket.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: to
|
||||
parent: Outputs
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `to()` function writes data to an **InfluxDB v2.0** bucket.
|
||||
|
||||
_**Function type:** Output_
|
||||
_**Output data type:** Object_
|
||||
|
||||
```js
|
||||
to(
|
||||
bucket: "my-bucket",
|
||||
org: "my-org",
|
||||
host: "http://example.com:8086",
|
||||
token: "xxxxxx",
|
||||
timeColumn: "_time",
|
||||
tagColumns: ["tag1", "tag2", "tag3"],
|
||||
fieldFn: (r) => ({ [r._field]: r._value })
|
||||
)
|
||||
|
||||
// OR
|
||||
|
||||
to(
|
||||
bucketID: "1234567890",
|
||||
orgID: "0987654321",
|
||||
host: "http://example.com:8086",
|
||||
token: "xxxxxx",
|
||||
timeColumn: "_time",
|
||||
tagColumns: ["tag1", "tag2", "tag3"],
|
||||
fieldFn: (r) => ({ [r._field]: r._value })
|
||||
)
|
||||
```
|
||||
|
||||
## Parameters
|
||||
{{% note %}}
|
||||
`bucket` OR `bucketID` is **required**.
|
||||
{{% /note %}}
|
||||
|
||||
### bucket
|
||||
The bucket to which data is written. Mutually exclusive with `bucketID`.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
### bucketID
|
||||
The ID of the bucket to which data is written. Mutually exclusive with `bucket`.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
### org
|
||||
The organization name of the specified [`bucket`](#bucket).
|
||||
Only required when writing to a remote host.
|
||||
Mutually exclusive with `orgID`
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
{{% note %}}
|
||||
Specify either an `org` or an `orgID`, but not both.
|
||||
{{% /note %}}
|
||||
|
||||
### orgID
|
||||
The organization ID of the specified [`bucket`](#bucket).
|
||||
Only required when writing to a remote host.
|
||||
Mutually exclusive with `org`.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
### host
|
||||
The remote InfluxDB host to which to write.
|
||||
_If specified, a `token` is required._
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
### token
|
||||
The authorization token to use when writing to a remote host.
|
||||
_Required when a `host` is specified._
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
### timeColumn
|
||||
The time column of the output.
|
||||
Default is `"_time"`.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
### tagColumns
|
||||
The tag columns of the output.
|
||||
Defaults to all columns with type `string`, excluding all value columns and the `_field` column if present.
|
||||
|
||||
_**Data type:** Array of strings_
|
||||
|
||||
### fieldFn
|
||||
Function that takes a record from the input table and returns an object.
|
||||
For each record from the input table, `fieldFn` returns an object that maps output the field key to the output value.
|
||||
Default is `(r) => ({ [r._field]: r._value })`
|
||||
|
||||
_**Data type:** Function_
|
||||
_**Output data type:** Object_
|
||||
|
||||
## Examples
|
||||
|
||||
### Default to() operation
|
||||
Given the following table:
|
||||
|
||||
| _time | _start | _stop | _measurement | _field | _value |
|
||||
| ----- | ------ | ----- | ------------ | ------ | ------ |
|
||||
| 0005 | 0000 | 0009 | "a" | "temp" | 100.1 |
|
||||
| 0006 | 0000 | 0009 | "a" | "temp" | 99.3 |
|
||||
| 0007 | 0000 | 0009 | "a" | "temp" | 99.9 |
|
||||
|
||||
The default `to` operation:
|
||||
|
||||
```js
|
||||
// ...
|
||||
|> to(bucket:"my-bucket", org:"my-org")
|
||||
```
|
||||
|
||||
is equivalent to writing the above data using the following line protocol:
|
||||
|
||||
```
|
||||
_measurement=a temp=100.1 0005
|
||||
_measurement=a temp=99.3 0006
|
||||
_measurement=a temp=99.9 0007
|
||||
```
|
||||
|
||||
### Custom to() operation
|
||||
The `to()` functions default operation can be overridden. For example, given the following table:
|
||||
|
||||
| _time | _start | _stop | tag1 | tag2 | hum | temp |
|
||||
| ----- | ------ | ----- | ---- | ---- | ---- | ----- |
|
||||
| 0005 | 0000 | 0009 | "a" | "b" | 55.3 | 100.1 |
|
||||
| 0006 | 0000 | 0009 | "a" | "b" | 55.4 | 99.3 |
|
||||
| 0007 | 0000 | 0009 | "a" | "b" | 55.5 | 99.9 |
|
||||
|
||||
The operation:
|
||||
|
||||
```js
|
||||
// ...
|
||||
|> to(bucket:"my-bucket", org:"my-org", tagColumns:["tag1"], fieldFn: (r) => return {"hum": r.hum, "temp": r.temp})
|
||||
```
|
||||
|
||||
is equivalent to writing the above data using the following line protocol:
|
||||
|
||||
```
|
||||
_tag1=a hum=55.3,temp=100.1 0005
|
||||
_tag1=a hum=55.4,temp=99.3 0006
|
||||
_tag1=a hum=55.5,temp=99.9 0007
|
||||
```
|
||||
|
||||
<hr style="margin-top:4rem"/>
|
||||
|
||||
##### Related InfluxQL functions and statements:
|
||||
[SELECT INTO](https://docs.influxdata.com/influxdb/latest/query_language/data_exploration/#the-into-clause)
|
|
@ -0,0 +1,45 @@
|
|||
---
|
||||
title: yield() function
|
||||
description: The yield() function indicates the input tables received should be delivered as a result of the query.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: yield
|
||||
parent: Outputs
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `yield()` function indicates the input tables received should be delivered as a result of the query.
|
||||
Yield outputs the input stream unmodified.
|
||||
A query may have multiple results, each identified by the name provided to the `yield()` function.
|
||||
|
||||
_**Function type:** Output_
|
||||
_**Output data type:** Object_
|
||||
|
||||
```js
|
||||
yield(name: "custom-name")
|
||||
```
|
||||
|
||||
{{% note %}}
|
||||
`yield()` is implicit for queries that do only one thing and are only needed when using multiple sources in a query.
|
||||
With multiple sources, `yield()` is required to specify what is returned, and what name to give it.
|
||||
{{% /note %}}
|
||||
|
||||
## Parameters
|
||||
|
||||
### name
|
||||
A unique name for the yielded results.
|
||||
Defaults to `"_results"`.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: -5m)
|
||||
|> yield(name: "1")
|
||||
```
|
||||
|
||||
<hr style="margin-top:4rem"/>
|
||||
|
||||
##### Related InfluxQL functions and statements:
|
||||
[SELECT AS](https://docs.influxdata.com/influxdb/latest/query_language/data_exploration/#the-basic-select-statement)
|
|
@ -0,0 +1,14 @@
|
|||
---
|
||||
title: Flux testing functions
|
||||
description: Flux testing functions test piped-forward data in specific ways and return errors if the tests fail.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: Tests
|
||||
parent: Flux functions
|
||||
weight: 5
|
||||
---
|
||||
|
||||
Flux testing functions test piped-forward data in specific ways and return errors if the tests fail.
|
||||
The following testing functions are available:
|
||||
|
||||
{{< function-list category="Tests" menu="v2_0_ref" >}}
|
|
@ -0,0 +1,67 @@
|
|||
---
|
||||
title: assertEquals() function
|
||||
description: The assertEquals() function tests whether two streams have identical data.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: assertEquals
|
||||
parent: Tests
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `assertEquals()` function tests whether two streams have identical data.
|
||||
If equal, the function outputs the tested data stream unchanged.
|
||||
If unequal, the function outputs an error.
|
||||
|
||||
_**Function type:** Test_
|
||||
|
||||
```js
|
||||
assertEquals(
|
||||
name: "streamEquality",
|
||||
got: got,
|
||||
want: want
|
||||
)
|
||||
```
|
||||
|
||||
_The `assertEquals()` function can be used to perform in-line tests in a query._
|
||||
|
||||
## Parameters
|
||||
|
||||
## name
|
||||
Unique name given to the assertion.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
## got
|
||||
The stream containing data to test.
|
||||
Defaults to data piped-forward from another function (`<-`).
|
||||
|
||||
_**Data type:** Object_
|
||||
|
||||
## want
|
||||
The stream that contains the expected data to test against.
|
||||
|
||||
_**Data type:** Object_
|
||||
|
||||
|
||||
## Examples
|
||||
|
||||
##### Assert of separate streams
|
||||
```js
|
||||
want = from(bucket: "backup-telegraf/autogen")
|
||||
|> range(start: -5m)
|
||||
|
||||
got = from(bucket: "telegraf/autogen")
|
||||
|> range(start: -5m)
|
||||
|
||||
assertEquals(got: got, want: want)
|
||||
```
|
||||
|
||||
##### Inline assertion
|
||||
```js
|
||||
want = from(bucket: "backup-telegraf/autogen")
|
||||
|> range(start: -5m)
|
||||
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: -5m)
|
||||
|> assertEquals(want: want)
|
||||
```
|
|
@ -0,0 +1,27 @@
|
|||
---
|
||||
title: Flux transformation functions
|
||||
description: Flux transformation functions transform and shape your data in specific ways.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
parent: Flux functions
|
||||
name: Transformations
|
||||
weight: 3
|
||||
---
|
||||
|
||||
Flux transformation functions transform or shape your data in specific ways.
|
||||
There are different types of transformations categorized below:
|
||||
|
||||
## [Aggregates](/v2.0/reference/flux/functions/transformations/aggregates)
|
||||
Aggregate functions take values from an input table and aggregate them in some way.
|
||||
The output table contains is a single row with the aggregated value.
|
||||
|
||||
## [Selectors](/v2.0/reference/flux/functions/transformations/selectors)
|
||||
Selector functions return one or more records based on function logic.
|
||||
The output table is different than the input table, but individual row values are not.
|
||||
|
||||
## [Type conversions](/v2.0/reference/flux/functions/transformations/type-conversions)
|
||||
Type conversion functions convert the `_value` column of the input table into a specific data type.
|
||||
|
||||
## Generic transformations
|
||||
|
||||
{{< function-list category="Transformations" menu="v2_0_ref" >}}
|
|
@ -0,0 +1,47 @@
|
|||
---
|
||||
title: Flux aggregate functions
|
||||
description: Flux aggregate functions take values from an input table and aggregate them in some way.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
parent: Transformations
|
||||
name: Aggregates
|
||||
weight: 1
|
||||
---
|
||||
|
||||
Flux aggregate functions take values from an input table and aggregate them in some way.
|
||||
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.
|
||||
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.
|
||||
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.
|
||||
- It will not have a `_time` column.
|
||||
|
||||
### aggregateWindow helper function
|
||||
The [`aggregateWindow()` function](/v2.0/reference/flux/functions/transformations/aggregates/aggregatewindow)
|
||||
does most of the work needed when aggregating data.
|
||||
It windows and aggregates the data, then combines windowed tables into a single output table.
|
||||
|
||||
### Aggregate functions
|
||||
The following aggregate functions are available:
|
||||
|
||||
{{< function-list category="Aggregates" menu="v2_0_ref" >}}
|
||||
|
||||
### Aggregate selectors
|
||||
The following functions are both aggregates and selectors.
|
||||
Each returns `n` values after performing an aggregate operation.
|
||||
They are categorized as selector functions in this documentation:
|
||||
|
||||
- [highestAverage](/v2.0/reference/flux/functions/transformations/selectors/highestaverage)
|
||||
- [highestCurrent](/v2.0/reference/flux/functions/transformations/selectors/highestcurrent)
|
||||
- [highestMax](/v2.0/reference/flux/functions/transformations/selectors/highestmax)
|
||||
- [lowestAverage](/v2.0/reference/flux/functions/transformations/selectors/lowestaverage)
|
||||
- [lowestCurrent](/v2.0/reference/flux/functions/transformations/selectors/lowestcurrent)
|
||||
- [lowestMin](/v2.0/reference/flux/functions/transformations/selectors/lowestmin)
|
|
@ -0,0 +1,112 @@
|
|||
---
|
||||
title: aggregateWindow() function
|
||||
description: The aggregateWindow() function applies an aggregate function to fixed windows of time.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: aggregateWindow
|
||||
parent: Aggregates
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `aggregateWindow()` function applies an aggregate function to fixed windows of time.
|
||||
|
||||
_**Function type:** Aggregate_
|
||||
|
||||
```js
|
||||
aggregateWindow(
|
||||
every: 1m,
|
||||
fn: mean,
|
||||
columns: ["_value"],
|
||||
timeColumn: "_stop",
|
||||
timeDst: "_time",
|
||||
createEmpty: true
|
||||
)
|
||||
```
|
||||
|
||||
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.
|
||||
View the [function definition](#function-definition).
|
||||
|
||||
## Parameters
|
||||
|
||||
### every
|
||||
The duration of windows.
|
||||
|
||||
_**Data type:** Duration_
|
||||
|
||||
### fn
|
||||
The aggregate function used in the operation.
|
||||
|
||||
_**Data type:** Function_
|
||||
|
||||
### columns
|
||||
List of columns on which to operate.
|
||||
Defaults to `["_value"]`.
|
||||
|
||||
_**Data type:** Array of strings_
|
||||
|
||||
### timeColumn
|
||||
The time column from which time is copied for the aggregate record.
|
||||
Defaults to `"_stop"`.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
### timeDst
|
||||
The "time destination" column to which time is copied for the aggregate record.
|
||||
Defaults to `"_time"`.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
### createEmpty
|
||||
For windows without data, this will create an empty window and fill
|
||||
it with a `null` aggregate value.
|
||||
Defaults to `true`.
|
||||
|
||||
_**Data type:** Boolean_
|
||||
|
||||
## Examples
|
||||
|
||||
###### Using an aggregate function with default parameters
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: 1h)
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "mem" and
|
||||
r._field == "used_percent")
|
||||
|> aggregateWindow(
|
||||
every: 5m,
|
||||
fn: mean
|
||||
)
|
||||
```
|
||||
####### Specifying parameters of the aggregate function
|
||||
To use `aggregateWindow()` aggregate functions that don't provide defaults for required parameters,
|
||||
for the `fn` parameter, define an anonymous function with `columns` and `tables` parameters
|
||||
that pipe-forwards tables into the aggregate function with all required parameters defined:
|
||||
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: 1h)
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "mem" and
|
||||
r._field == "used_percent")
|
||||
|> aggregateWindow(
|
||||
every: 5m,
|
||||
fn: (columns, tables=<-) => tables |> percentile(percentile: 0.99, columns:columns)
|
||||
)
|
||||
```
|
||||
|
||||
## Function definition
|
||||
```js
|
||||
aggregateWindow = (every, fn, columns=["_value"], timeColumn="_stop", timeDst="_time", tables=<-) =>
|
||||
tables
|
||||
|> window(every:every)
|
||||
|> fn(columns:columns)
|
||||
|> duplicate(column:timeColumn, as:timeDst)
|
||||
|> window(every:inf, timeColumn:timeDst)
|
||||
```
|
||||
|
||||
<hr style="margin-top:4rem"/>
|
||||
|
||||
##### Related InfluxQL functions and statements:
|
||||
[InfluxQL aggregate functions](https://docs.influxdata.com/influxdb/latest/query_language/functions/#aggregations)
|
||||
[GROUP BY time()](https://docs.influxdata.com/influxdb/latest/query_language/data_exploration/#the-group-by-clause)
|
|
@ -0,0 +1,45 @@
|
|||
---
|
||||
title: count() function
|
||||
description: The count() function outputs the number of non-null records in each aggregated column.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: count
|
||||
parent: Aggregates
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `count()` function outputs the number of records in each aggregated column.
|
||||
It counts both null and non-null records.
|
||||
|
||||
_**Function type:** Aggregate_
|
||||
_**Output data type:** Integer_
|
||||
|
||||
```js
|
||||
count(columns: ["_value"])
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### columns
|
||||
A list of columns on which to operate
|
||||
Defaults to `["_value"]`.
|
||||
|
||||
_**Data type: Array of strings**_
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: -5m)
|
||||
|> count()
|
||||
```
|
||||
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: -5m)
|
||||
|> count(columns: ["_value"])
|
||||
```
|
||||
|
||||
<hr style="margin-top:4rem"/>
|
||||
|
||||
##### Related InfluxQL functions and statements:
|
||||
[COUNT()](https://docs.influxdata.com/influxdb/latest/query_language/functions/#count)
|
|
@ -0,0 +1,67 @@
|
|||
---
|
||||
title: cov() function
|
||||
description: The cov() function computes the covariance between two streams by first joining the streams, then performing the covariance operation.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: cov
|
||||
parent: Aggregates
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `cov()` function computes the covariance between two streams by first joining the streams,
|
||||
then performing the covariance operation.
|
||||
|
||||
_**Function type:** Aggregate
|
||||
_**Output data type:** Float_
|
||||
|
||||
```js
|
||||
cov(x: table1, y: table2, on: ["_time", "_field"], pearsonr: false)
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### x
|
||||
One input stream used to calculate the covariance.
|
||||
|
||||
_**Data type:** Object_
|
||||
|
||||
### y
|
||||
The other input table used to calculate the covariance.
|
||||
|
||||
_**Data type:** Object_
|
||||
|
||||
### on
|
||||
The list of columns on which to join.
|
||||
|
||||
_**Data type:** Array of strings_
|
||||
|
||||
### pearsonr
|
||||
Indicates whether the result should be normalized to be the Pearson R coefficient.
|
||||
|
||||
_**Data type:** Boolean_
|
||||
|
||||
|
||||
## Examples
|
||||
|
||||
```js
|
||||
table1 = from(bucket: "telegraf/autogen")
|
||||
|> range(start: -15m)
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "measurement_1"
|
||||
)
|
||||
|
||||
table2 = from(bucket: "telegraf/autogen")
|
||||
|> range(start: -15m)
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "measurement_2"
|
||||
)
|
||||
|
||||
cov(x: table1, y: table2, on: ["_time", "_field"])
|
||||
```
|
||||
|
||||
## Function definition
|
||||
```js
|
||||
cov = (x,y,on,pearsonr=false) =>
|
||||
join( tables:{x:x, y:y}, on:on )
|
||||
|> covariance(pearsonr:pearsonr, columns:["_value_x","_value_y"])
|
||||
```
|
|
@ -0,0 +1,46 @@
|
|||
---
|
||||
title: covariance() function
|
||||
description: The covariance() function computes the covariance between two columns.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: covariance
|
||||
parent: Aggregates
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `covariance()` function computes the covariance between two columns.
|
||||
|
||||
_**Function type:** Aggregate_
|
||||
_**Output data type:** Float_
|
||||
|
||||
```js
|
||||
covariance(columns: ["column_x", "column_y"], pearsonr: false, valueDst: "_value")
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### columns
|
||||
A list of columns on which to operate.
|
||||
|
||||
_**Data type:** Array of strings_
|
||||
|
||||
{{% note %}}
|
||||
Exactly two columns must be provided to the `columns` property.
|
||||
{{% /note %}}
|
||||
|
||||
### pearsonr
|
||||
Indicates whether the result should be normalized to be the Pearson R coefficient.
|
||||
|
||||
_**Data type:** Boolean_
|
||||
|
||||
### valueDst
|
||||
The column into which the result will be placed. Defaults to `"_value"`.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start:-5m)
|
||||
|> covariance(columns: ["x", "y"])
|
||||
```
|
|
@ -0,0 +1,63 @@
|
|||
---
|
||||
title: derivative() function
|
||||
description: The derivative() function computes the rate of change per unit of time between subsequent non-null records.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: derivative
|
||||
parent: Aggregates
|
||||
weight: 1
|
||||
---
|
||||
|
||||
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.
|
||||
|
||||
_**Function type:** Aggregate_
|
||||
_**Output data type:** Float_
|
||||
|
||||
```js
|
||||
derivative(
|
||||
unit: 1s,
|
||||
nonNegative: false,
|
||||
columns: ["_value"],
|
||||
timeSrc: "_time"
|
||||
)
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### unit
|
||||
The time duration used when creating the derivative.
|
||||
Defaults to `1s`.
|
||||
|
||||
_**Data type:** Duration_
|
||||
|
||||
### nonNegative
|
||||
Indicates if the derivative is allowed to be negative.
|
||||
When set to `true`, if a value is less than the previous value, it is assumed the previous value should have been a zero.
|
||||
|
||||
_**Data type:** Boolean_
|
||||
|
||||
### columns
|
||||
A list of columns on which to compute the derivative.
|
||||
Defaults to `["_value"]`.
|
||||
|
||||
_**Data type:** Array of strings_
|
||||
|
||||
### timeSrc
|
||||
The column containing time values.
|
||||
Defaults to `"_time"`.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: -5m)
|
||||
|> derivative(unit: 1s, nonNegative: true)
|
||||
```
|
||||
|
||||
<hr style="margin-top:4rem"/>
|
||||
|
||||
##### Related InfluxQL functions and statements:
|
||||
[DERIVATIVE()](https://docs.influxdata.com/influxdb/latest/query_language/functions/#derivative)
|
|
@ -0,0 +1,94 @@
|
|||
---
|
||||
title: difference() function
|
||||
description: The difference() function computes the difference between subsequent non-null records.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: difference
|
||||
parent: Aggregates
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `difference()` function computes the difference between subsequent records.
|
||||
Every 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"])
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### nonNegative
|
||||
Indicates if the difference is allowed to be negative.
|
||||
When set to `true`, if a value is less than the previous value, it is assumed the previous value should have been a zero.
|
||||
|
||||
_**Data type:** Boolean_
|
||||
|
||||
### columns
|
||||
A list of columns on which to compute the difference.
|
||||
Defaults to `["_value"]`.
|
||||
|
||||
_**Data type:** Array of strings_
|
||||
|
||||
## Subtraction rules for numeric types
|
||||
- The difference between two non-null values is their algebraic difference;
|
||||
or `null`, if the result is negative and `nonNegative: true`;
|
||||
- `null` minus some value is always `null`;
|
||||
- Some value `v` minus `null` is `v` minus the last non-null value seen before `v`;
|
||||
or `null` if `v` is the first non-null value seen.
|
||||
|
||||
|
||||
## Examples
|
||||
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: -5m)
|
||||
|> difference()
|
||||
```
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: -5m)
|
||||
|> difference(nonNegative: true)
|
||||
```
|
||||
|
||||
### 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 |
|
||||
|
||||
#### 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 |
|
||||
|
||||
#### 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 |
|
||||
|
||||
<hr style="margin-top:4rem"/>
|
||||
|
||||
##### Related InfluxQL functions and statements:
|
||||
[DIFFERENCE()](https://docs.influxdata.com/influxdb/latest/query_language/functions/#difference)
|
|
@ -0,0 +1,83 @@
|
|||
---
|
||||
title: histogramQuantile() function
|
||||
description: The `histogramQuantile()` function approximates a quantile given a histogram that approximates the cumulative distribution of the dataset.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: histogramQuantile
|
||||
parent: Aggregates
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `histogramQuantile()` function approximates a quantile given a histogram that
|
||||
approximates the cumulative distribution of the dataset.
|
||||
Each input table represents a single histogram.
|
||||
The histogram tables must have two columns – a count column and an upper bound column.
|
||||
|
||||
The count is the number of values that are less than or equal to the upper bound value.
|
||||
The table can have any number of records, each representing an entry in the histogram.
|
||||
The counts must be monotonically increasing when sorted by upper bound.
|
||||
If any values in the count column or upper bound column are `null`, it returns an error.
|
||||
|
||||
Linear interpolation between the two closest bounds is used to compute the quantile.
|
||||
If the either of the bounds used in interpolation are infinite,
|
||||
then the other finite bound is used and no interpolation is performed.
|
||||
|
||||
The output table has the same group key as the input table.
|
||||
Columns not part of the group key are removed and a single value column of type float is added.
|
||||
The count and upper bound columns must not be part of the group key.
|
||||
The value column represents the value of the desired quantile from the histogram.
|
||||
|
||||
_**Function type:** Aggregate_
|
||||
_**Output data type:** Float_
|
||||
|
||||
```js
|
||||
histogramQuantile(quantile: 0.5, countColumn: "_value", upperBoundColumn: "le", valueColumn: "_value", minValue: 0)
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### quantile
|
||||
A value between 0 and 1 indicating the desired quantile to compute.
|
||||
|
||||
_**Data type:** Float_
|
||||
|
||||
### countColumn
|
||||
The name of the column containing the histogram counts.
|
||||
The count column type must be float.
|
||||
Defaults to `"_value"`.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
### upperBoundColumn
|
||||
The name of the column containing the histogram upper bounds.
|
||||
The upper bound column type must be float.
|
||||
Defaults to `"le"`.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
### valueColumn
|
||||
The name of the output column which will contain the computed quantile.
|
||||
Defaults to `"_value"`.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
### minValue
|
||||
The assumed minimum value of the dataset.
|
||||
When the quantile falls below the lowest upper bound, interpolation is performed between `minValue` and the lowest upper bound.
|
||||
When `minValue` is equal to negative infinity, the lowest upper bound is used.
|
||||
Defaults to `0`.
|
||||
|
||||
_**Data type:** Float_
|
||||
|
||||
{{% note %}}
|
||||
When the quantile falls below the lowest upper bound,
|
||||
interpolation is performed between `minValue` and the lowest upper bound.
|
||||
When `minValue` is equal to negative infinity, the lowest upper bound is used.
|
||||
{{% /note %}}
|
||||
|
||||
## Examples
|
||||
|
||||
##### Compute the 90th quantile
|
||||
```js
|
||||
histogramQuantile(quantile: 0.9)
|
||||
```
|
|
@ -0,0 +1,66 @@
|
|||
---
|
||||
title: increase() function
|
||||
description: The increase() function calculates the total non-negative difference between values in a table.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: increase
|
||||
parent: Aggregates
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `increase()` function calculates the total non-negative difference between values in a table.
|
||||
A main use case is tracking changes in counter values which may wrap over time
|
||||
when they hit a threshold or are reset.
|
||||
In the case of a wrap/reset, we can assume that the absolute delta between two
|
||||
points will be at least their non-negative difference.
|
||||
|
||||
_**Function type:** Aggregate_
|
||||
_**Output data type:** Float_
|
||||
|
||||
```js
|
||||
increase(columns: ["_values"])
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### columns
|
||||
The list of columns for which the increase is calculated.
|
||||
Defaults to `["_value"]`.
|
||||
|
||||
_**Data type:** Array of strings_
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: -24h)
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "system" and
|
||||
r._field == "n_users"
|
||||
)
|
||||
|> increase()
|
||||
```
|
||||
|
||||
Given the following input table:
|
||||
|
||||
| _time | _value |
|
||||
| ----- | ------ |
|
||||
| 00001 | 1 |
|
||||
| 00002 | 5 |
|
||||
| 00003 | 3 |
|
||||
| 00004 | 4 |
|
||||
|
||||
`increase()` produces the following table:
|
||||
|
||||
| _time | _value |
|
||||
| ----- | ------ |
|
||||
| 00002 | 4 |
|
||||
| 00003 | 7 |
|
||||
| 00004 | 8 |
|
||||
|
||||
## Function definition
|
||||
```js
|
||||
increase = (tables=<-, columns=["_value"]) =>
|
||||
tables
|
||||
|> difference(nonNegative: true, columns:columns)
|
||||
|> cumulativeSum()
|
||||
```
|
|
@ -0,0 +1,48 @@
|
|||
---
|
||||
title: integral() function
|
||||
description: The integral() function computes the area under the curve per unit of time of subsequent non-null records.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: integral
|
||||
parent: Aggregates
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `integral()` function computes the area under the curve per [`unit`](#unit) of time of subsequent non-null records.
|
||||
The curve is defined using `_time` as the domain and record values as the range.
|
||||
|
||||
_**Function type:** Aggregate_
|
||||
_**Output data type:** Float_
|
||||
|
||||
```js
|
||||
integral(unit: 10s, columns: ["_value"])
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### unit
|
||||
The time duration used when computing the integral.
|
||||
|
||||
_**Data type:** Duration_
|
||||
|
||||
### columns
|
||||
A list of columns on which to operate.
|
||||
Defaults to `["_value"]`.
|
||||
|
||||
_**Data type:** Array of strings_
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: -5m)
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "cpu" and
|
||||
r._field == "usage_system"
|
||||
)
|
||||
|> integral(unit:10s)
|
||||
```
|
||||
|
||||
<hr style="margin-top:4rem"/>
|
||||
|
||||
##### Related InfluxQL functions and statements:
|
||||
[INTEGRAL()](https://docs.influxdata.com/influxdb/latest/query_language/functions/#integral)
|
|
@ -0,0 +1,42 @@
|
|||
---
|
||||
title: mean() function
|
||||
description: The mean() function computes the mean or average of non-null records in the input table.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: mean
|
||||
parent: Aggregates
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `mean()` function computes the mean or average of non-null records in the input table.
|
||||
|
||||
_**Function type:** Aggregate_
|
||||
_**Output data type:** Float_
|
||||
|
||||
```js
|
||||
mean(columns: ["_value"])
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### columns
|
||||
A list of columns on which to compute the mean.
|
||||
Defaults to `["_value"]`.
|
||||
|
||||
_**Data type:** Array of strings_
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket:"telegraf/autogen")
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "mem" and
|
||||
r._field == "used_percent")
|
||||
|> range(start:-12h)
|
||||
|> window(every:10m)
|
||||
|> mean()
|
||||
```
|
||||
|
||||
<hr style="margin-top:4rem"/>
|
||||
|
||||
##### Related InfluxQL functions and statements:
|
||||
[MEAN()](https://docs.influxdata.com/influxdb/latest/query_language/functions/#mean)
|
|
@ -0,0 +1,97 @@
|
|||
---
|
||||
title: median() function
|
||||
description: The `median()` function returns the median `_value` of an input table or all non-null records in the input table with values that fall within the 50th percentile.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: median
|
||||
parent: Aggregates
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `median()` function is a special application of the [`percentile()` function](/v2.0/reference/flux/functions/transformations/aggregates/percentile)
|
||||
that returns the median `_value` of an input table or all non-null records in the input table
|
||||
with values that fall within the 50th percentile depending on the [method](#method) used.
|
||||
|
||||
_**Function type:** Selector or Aggregate_
|
||||
_**Output data type:** Object_
|
||||
|
||||
|
||||
```js
|
||||
median(method: "estimate_tdigest", compression: 0.0)
|
||||
```
|
||||
|
||||
When using the `estimate_tdigest` or `exact_mean` methods, it outputs non-null
|
||||
records with values that fall within the 50th percentile.
|
||||
|
||||
When using the `exact_selector` method, it outputs the non-null record with the
|
||||
value that represents the 50th percentile.
|
||||
|
||||
{{% note %}}
|
||||
The `median()` function can only be used with float value types.
|
||||
It is a special application of the [`percentile()` function](/v2.0/reference/flux/functions/transformations/aggregates/percentile) which
|
||||
uses an approximation implementation that requires floats.
|
||||
You can convert your value column to a float column using the [`toFloat()` function](/v2.0/reference/flux/functions/transformations/type-conversions/tofloat).
|
||||
{{% /note %}}
|
||||
|
||||
## Parameters
|
||||
|
||||
### method
|
||||
Defines the method of computation. Defaults to `"estimate_tdigest"`.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
The available options are:
|
||||
|
||||
##### estimate_tdigest
|
||||
An aggregate method that uses a [t-digest data structure](https://github.com/tdunning/t-digest)
|
||||
to compute an accurate percentile estimate on large data sources.
|
||||
|
||||
##### exact_mean
|
||||
An aggregate method that takes the average of the two points closest to the percentile value.
|
||||
|
||||
##### exact_selector
|
||||
A selector method that returns the data point for which at least percentile points are less than.
|
||||
|
||||
### compression
|
||||
Indicates how many centroids to use when compressing the dataset.
|
||||
A larger number produces a more accurate result at the cost of increased memory requirements.
|
||||
Defaults to 1000.
|
||||
|
||||
_**Data type:** Float_
|
||||
|
||||
## Examples
|
||||
|
||||
###### Median as an aggregate
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "mem" and
|
||||
r._field == "used_percent"
|
||||
)
|
||||
|> range(start:-12h)
|
||||
|> window(every:10m)
|
||||
|> median()
|
||||
```
|
||||
|
||||
###### Median as a selector
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "mem" and
|
||||
r._field == "used_percent"
|
||||
)
|
||||
|> range(start:-12h)
|
||||
|> window(every:10m)
|
||||
|> median(method: "exact_selector")
|
||||
```
|
||||
|
||||
## Function definition
|
||||
```js
|
||||
median = (method="estimate_tdigest", compression=0.0, tables=<-) =>
|
||||
percentile(percentile:0.5, method:method, compression:compression)
|
||||
```
|
||||
|
||||
<hr style="margin-top:4rem"/>
|
||||
|
||||
##### Related InfluxQL functions and statements:
|
||||
[MEDIAN()](https://docs.influxdata.com/influxdb/latest/query_language/functions/#median)
|
|
@ -0,0 +1,61 @@
|
|||
---
|
||||
title: pearsonr() function
|
||||
description: The pearsonr() function computes the Pearson R correlation coefficient between two streams by first joining the streams, then performing the covariance operation normalized to compute R.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: pearsonr
|
||||
parent: Aggregates
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `pearsonr()` function computes the Pearson R correlation coefficient between two streams
|
||||
by first joining the streams, then performing the covariance operation normalized to compute R.
|
||||
|
||||
_**Function type:** Aggregate_
|
||||
_**Output data type:** Float_
|
||||
|
||||
```js
|
||||
pearsonr(x: stream1, y: stream2, on: ["_time", "_field"])
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### x
|
||||
First input stream used in the operation.
|
||||
|
||||
_**Data type:** Object_
|
||||
|
||||
### y
|
||||
Second input stream used in the operation.
|
||||
|
||||
_**Data type:** Object_
|
||||
|
||||
### on
|
||||
The list of columns on which to join.
|
||||
|
||||
_**Data type:** Array of strings_
|
||||
|
||||
## Examples
|
||||
```js
|
||||
stream1 = from(bucket:"telegraf/autogen")
|
||||
|> range(start:-15m)
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "mem" and
|
||||
r._field == "used"
|
||||
)
|
||||
|
||||
stream2 = from(bucket:"telegraf/autogen")
|
||||
|> range(start:-15m)
|
||||
|> filter(fn: (r) => r
|
||||
._measurement == "mem" and
|
||||
r._field == "available"
|
||||
)
|
||||
|
||||
pearsonr(x: stream1, y: stream2, on: ["_time", "_field"])
|
||||
```
|
||||
|
||||
## Function definition
|
||||
```js
|
||||
pearsonr = (x,y,on) =>
|
||||
cov(x:x, y:y, on:on, pearsonr:true)
|
||||
```
|
|
@ -0,0 +1,97 @@
|
|||
---
|
||||
title: percentile() function
|
||||
description: The percentile() function outputs non-null records with values that fall within the specified percentile or the non-null record with the value that represents the specified percentile.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: percentile
|
||||
parent: Aggregates
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `percentile()` function returns records from an input table with `_value`s that fall within
|
||||
a specified percentile or it returns the record with the `_value` that represents the specified percentile.
|
||||
Which it returns depends on the [method](#method) used.
|
||||
|
||||
_**Function type:** Aggregate or Selector_
|
||||
_**Output data type:** Float or Object_
|
||||
|
||||
```js
|
||||
percentile(columns: ["_value"], percentile: 0.99, method: "estimate_tdigest", compression: 1000)
|
||||
```
|
||||
|
||||
When using the `estimate_tdigest` or `exact_mean` methods, it outputs non-null
|
||||
records with values that fall within the specified percentile.
|
||||
|
||||
When using the `exact_selector` method, it outputs the non-null record with the
|
||||
value that represents the specified percentile.
|
||||
|
||||
## Parameters
|
||||
|
||||
### columns
|
||||
A list of columns on which to compute the percentile.
|
||||
Defaults to `["_value"]`.
|
||||
|
||||
_**Data type:** Array of strings_
|
||||
|
||||
### percentile
|
||||
A value between 0 and 1 indicating the desired percentile.
|
||||
|
||||
_**Data type:** Float_
|
||||
|
||||
### method
|
||||
Defines the method of computation.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
The available options are:
|
||||
|
||||
##### estimate_tdigest
|
||||
An aggregate method that uses a [t-digest data structure](https://github.com/tdunning/t-digest)
|
||||
to compute an accurate percentile estimate on large data sources.
|
||||
|
||||
##### exact_mean
|
||||
An aggregate method that takes the average of the two points closest to the percentile value.
|
||||
|
||||
##### exact_selector
|
||||
A selector method that returns the data point for which at least percentile points are less than.
|
||||
|
||||
### compression
|
||||
Indicates how many centroids to use when compressing the dataset.
|
||||
A larger number produces a more accurate result at the cost of increased memory requirements.
|
||||
Defaults to 1000.
|
||||
|
||||
_**Data type:** Float_
|
||||
|
||||
## Examples
|
||||
|
||||
###### Percentile as an aggregate
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: -5m)
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "cpu" and
|
||||
r._field == "usage_system")
|
||||
|> percentile(
|
||||
percentile: 0.99,
|
||||
method: "estimate_tdigest",
|
||||
compression: 1000
|
||||
)
|
||||
```
|
||||
|
||||
###### Percentile as a selector
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: -5m)
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "cpu" and
|
||||
r._field == "usage_system")
|
||||
|> percentile(
|
||||
percentile: 0.99,
|
||||
method: "exact_selector"
|
||||
)
|
||||
```
|
||||
|
||||
<hr style="margin-top:4rem"/>
|
||||
|
||||
##### Related InfluxQL functions and statements:
|
||||
[PERCENTILE()](https://docs.influxdata.com/influxdb/latest/query_language/functions/#percentile)
|
|
@ -0,0 +1,36 @@
|
|||
---
|
||||
title: skew() function
|
||||
description: The skew() function outputs the skew of non-null records as a float.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: skew
|
||||
parent: Aggregates
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `skew()` function outputs the skew of non-null records as a float.
|
||||
|
||||
_**Function type:** Aggregate_
|
||||
_**Output data type:** Float_
|
||||
|
||||
```js
|
||||
skew(columns: ["_value"])
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### columns
|
||||
Specifies a list of columns on which to operate. Defaults to `["_value"]`.
|
||||
|
||||
_**Data type:** Array of strings_
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: -5m)
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "cpu" and
|
||||
r._field == "usage_system"
|
||||
)
|
||||
|> skew()
|
||||
```
|
|
@ -0,0 +1,46 @@
|
|||
---
|
||||
title: spread() function
|
||||
description: The spread() function outputs the difference between the minimum and maximum values in each specified column.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: spread
|
||||
parent: Aggregates
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `spread()` function outputs the difference between the minimum and maximum values in each 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.
|
||||
|
||||
_**Function type:** Aggregate_
|
||||
_**Output data type:** Integer or Float (inherited from input column type)_
|
||||
|
||||
```js
|
||||
spread(columns: ["_value"])
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### columns
|
||||
Specifies a list of columns on which to operate. Defaults to `["_value"]`.
|
||||
|
||||
_**Data type:** Array of strings_
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: -5m)
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "cpu" and
|
||||
r._field == "usage_system"
|
||||
)
|
||||
|> spread()
|
||||
```
|
||||
|
||||
<hr style="margin-top:4rem"/>
|
||||
|
||||
##### Related InfluxQL functions and statements:
|
||||
[SPREAD()](https://docs.influxdata.com/influxdb/latest/query_language/functions/#spread)
|
|
@ -0,0 +1,42 @@
|
|||
---
|
||||
title: stddev() function
|
||||
description: The stddev() function computes the standard deviation of non-null records in specified columns.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: stddev
|
||||
parent: Aggregates
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `stddev()` function computes the standard deviation of non-null records in specified columns.
|
||||
|
||||
_**Function type:** Aggregate_
|
||||
_**Output data type:** Float_
|
||||
|
||||
```js
|
||||
stddev(columns: ["_value"])
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### columns
|
||||
Specifies a list of columns on which to operate.
|
||||
Defaults to `["_value"]`.
|
||||
|
||||
_**Data type:** Array of strings_
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: -5m)
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "cpu" and
|
||||
r._field == "usage_system"
|
||||
)
|
||||
|> stddev()
|
||||
```
|
||||
|
||||
<hr style="margin-top:4rem"/>
|
||||
|
||||
##### Related InfluxQL functions and statements:
|
||||
[STDDEV()](https://docs.influxdata.com/influxdb/latest/query_language/functions/#stddev)
|
|
@ -0,0 +1,42 @@
|
|||
---
|
||||
title: sum() function
|
||||
description: The sum() function computes the sum of non-null records in specified columns.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: sum
|
||||
parent: Aggregates
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `sum()` function computes the sum of non-null records in specified columns.
|
||||
|
||||
_**Function type:** Aggregate_
|
||||
_**Output data type:** Integer, UInteger, or Float (inherited from column type)_
|
||||
|
||||
```js
|
||||
sum(columns: ["_value"])
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### columns
|
||||
Specifies a list of columns on which to operate.
|
||||
Defaults to `["_value"]`.
|
||||
|
||||
_**Data type:** Array of strings_
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: -5m)
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "cpu" and
|
||||
r._field == "usage_system"
|
||||
)
|
||||
|> sum()
|
||||
```
|
||||
|
||||
<hr style="margin-top:4rem"/>
|
||||
|
||||
##### Related InfluxQL functions and statements:
|
||||
[SUM()](https://docs.influxdata.com/influxdb/latest/query_language/functions/#sum)
|
|
@ -0,0 +1,57 @@
|
|||
---
|
||||
title: columns() function
|
||||
description: >
|
||||
The columns() function lists the column labels of input tables.
|
||||
For each input table, it outputs a table with the same group key columns,
|
||||
plus a new column containing the labels of the input table's columns.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: columns
|
||||
parent: Transformations
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `columns()` function lists the column labels of input tables.
|
||||
For each input table, it outputs a table with the same group key columns,
|
||||
plus a new column containing the labels of the input table's columns.
|
||||
Each row in an output table contains the group key value and the label of one column of the input table.
|
||||
Each output table has the same number of rows as the number of columns of the input table.
|
||||
|
||||
_**Function type:** Transformation_
|
||||
|
||||
```js
|
||||
columns(column: "_value")
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### column
|
||||
The name of the output column in which to store the column labels.
|
||||
Defaults to `"_value"`.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: -30m)
|
||||
|> columns(column: "labels")
|
||||
```
|
||||
|
||||
##### Get every possible column label in a single table
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: -30m)
|
||||
|> columns()
|
||||
|> keep(columns: ["_value"])
|
||||
|> group()
|
||||
|> distinct()
|
||||
```
|
||||
|
||||
<hr style="margin-top:4rem"/>
|
||||
|
||||
##### Related InfluxQL functions and statements:
|
||||
[SHOW MEASUREMENTS](https://docs.influxdata.com/influxdb/latest/query_language/schema_exploration/#show-measurements)
|
||||
[SHOW FIELD KEYS](https://docs.influxdata.com/influxdb/latest/query_language/schema_exploration/#show-field-keys)
|
||||
[SHOW TAG KEYS](https://docs.influxdata.com/influxdb/latest/query_language/schema_exploration/#show-tag-keys)
|
||||
[SHOW SERIES](https://docs.influxdata.com/influxdb/latest/query_language/schema_exploration/#show-tag-keys)
|
|
@ -0,0 +1,43 @@
|
|||
---
|
||||
title: cumulativeSum() function
|
||||
description: The cumulativeSum() function computes a running sum for non-null records in the table.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: cumulativeSum
|
||||
parent: Transformations
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `cumulativeSum()` function computes a running sum for non-null records in the table.
|
||||
The output table schema will be the same as the input table.
|
||||
|
||||
_**Function type:** Transformation
|
||||
_**Output data type:** Float_
|
||||
|
||||
```js
|
||||
cumulativeSum(columns: ["_value"])
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### columns
|
||||
A list of columns on which to operate.
|
||||
Defaults to `["_value"]`.
|
||||
|
||||
_**Data type:** Array of strings_
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: -5m)
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "disk" and
|
||||
r._field == "used_percent"
|
||||
)
|
||||
|> cumulativeSum(columns: ["_value"])
|
||||
```
|
||||
|
||||
<hr style="margin-top:4rem"/>
|
||||
|
||||
##### Related InfluxQL functions and statements:
|
||||
[CUMULATIVE_SUM()](https://docs.influxdata.com/influxdb/latest/query_language/functions/#cumulative-sum)
|
|
@ -0,0 +1,61 @@
|
|||
---
|
||||
title: drop() function
|
||||
description: The drop() function removes specified columns from a table.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: drop
|
||||
parent: Transformations
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `drop()` function removes specified columns from a table.
|
||||
Columns are specified either through a list or a predicate function.
|
||||
When a dropped column is part of the group key, it will be removed from the key.
|
||||
If a specified column is not present in a table, it will return an error.
|
||||
|
||||
_**Function type:** Transformation_
|
||||
_**Output data type:** Object_
|
||||
|
||||
```js
|
||||
drop(columns: ["col1", "col2"])
|
||||
|
||||
// OR
|
||||
|
||||
drop(fn: (column) => column =~ /usage*/)
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### columns
|
||||
Columns to be removed from the table.
|
||||
Cannot be used with `fn`.
|
||||
|
||||
_**Data type:** Array of strings_
|
||||
|
||||
### fn
|
||||
A predicate function which takes a column name as a parameter (`column`) and returns
|
||||
a boolean indicating whether or not the column should be removed from the table.
|
||||
Cannot be used with `columns`.
|
||||
|
||||
_**Data type:** Function_
|
||||
|
||||
## Examples
|
||||
|
||||
##### Drop a list of columns
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: -5m)
|
||||
|> drop(columns: ["host", "_measurement"])
|
||||
```
|
||||
|
||||
##### Drop columns matching a predicate
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: -5m)
|
||||
|> drop(fn: (column) => column =~ /usage*/)
|
||||
```
|
||||
|
||||
<hr style="margin-top:4rem"/>
|
||||
|
||||
##### Related InfluxQL functions and statements:
|
||||
[DROP MEASUREMENT](https://docs.influxdata.com/influxdb/latest/query_language/database_management/#delete-measurements-with-drop-measurement)
|
|
@ -0,0 +1,40 @@
|
|||
---
|
||||
title: duplicate() function
|
||||
description: The duplicate() function duplicates a specified column in a table.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: duplicate
|
||||
parent: Transformations
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `duplicate()` function duplicates a specified column in a table.
|
||||
If the specified column is part of the group key, it will be duplicated, but will
|
||||
not be part of the output table's group key.
|
||||
|
||||
_**Function type:** Transformation_
|
||||
_**Output data type:** Object_
|
||||
|
||||
```js
|
||||
duplicate(column: "column-name", as: "duplicate-name")
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### column
|
||||
The column to duplicate.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
### as
|
||||
The name assigned to the duplicate column.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start:-5m)
|
||||
|> filter(fn: (r) => r._measurement == "cpu")
|
||||
|> duplicate(column: "host", as: "server")
|
||||
```
|
|
@ -0,0 +1,72 @@
|
|||
---
|
||||
title: fill() function
|
||||
description: The fill() function filters data based on conditions defined in a predicate function (fn).
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: fill
|
||||
parent: Transformations
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `filter()` function replaces all null values in an input stream and replace them with a non-null value.
|
||||
The output stream is the same as the input stream with all null values replaced in the specified column.
|
||||
|
||||
_**Function type:** Transformation_
|
||||
|
||||
```js
|
||||
fill(column: "_value", value: 0.0)
|
||||
|
||||
// OR
|
||||
|
||||
fill(column: "_value", usePrevious: true)
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### column
|
||||
The column in which to replace null values. Defaults to `"_value"`.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
### value
|
||||
The constant value to use in place of nulls.
|
||||
The value type must match the value type of the `column`.
|
||||
|
||||
_**Data type:** Boolean | Integer | UInteger | Float | String | Time | Duration_
|
||||
|
||||
### usePrevious
|
||||
When `true`, assigns the value set in the previous non-null row.
|
||||
|
||||
> Cannot be used with `value`.
|
||||
|
||||
_**Data type:** Boolean | Integer | UInteger | Float | String | Time | Duration_
|
||||
|
||||
|
||||
## Examples
|
||||
|
||||
##### Fill null values with a specified non-null value
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: -1h)
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "cpu" and
|
||||
r.cpu == "cpu-total"
|
||||
)
|
||||
|> fill(value: 0.0)
|
||||
```
|
||||
|
||||
##### Fill null values with the previous non-null value
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: -1h)
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "cpu" and
|
||||
r.cpu == "cpu-total"
|
||||
)
|
||||
|> fill(usePrevious: true)
|
||||
```
|
||||
|
||||
<hr style="margin-top:4rem"/>
|
||||
|
||||
##### Related InfluxQL functions and statements:
|
||||
[FILL](https://docs.influxdata.com/influxdb/latest/query_language/data_exploration/#group-by-time-intervals-and-fill)
|
|
@ -0,0 +1,48 @@
|
|||
---
|
||||
title: filter() function
|
||||
description: The filter() function filters data based on conditions defined in a predicate function (fn).
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: filter
|
||||
parent: Transformations
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `filter()` function filters data based on conditions defined in a predicate function ([`fn`](#fn)).
|
||||
The output tables have the same schema as the corresponding input tables.
|
||||
|
||||
_**Function type:** Transformation_
|
||||
_**Output data type:** Object_
|
||||
|
||||
```js
|
||||
filter(fn: (r) => r._measurement == "cpu")
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### fn
|
||||
A single argument function that evaluates true or false.
|
||||
Records are passed to the function.
|
||||
Those that evaluate to true are included in the output tables.
|
||||
|
||||
_**Data type:** Function_
|
||||
|
||||
{{% note %}}
|
||||
Objects evaluated in `fn` functions are represented by `r`, short for "record" or "row".
|
||||
{{% /note %}}
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket:"telegraf/autogen")
|
||||
|> range(start:-1h)
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "cpu" and
|
||||
r._field == "usage_system" and
|
||||
r.cpu == "cpu-total"
|
||||
)
|
||||
```
|
||||
|
||||
<hr style="margin-top:4rem"/>
|
||||
|
||||
##### Related InfluxQL functions and statements:
|
||||
[SELECT](https://docs.influxdata.com/influxdb/latest/query_language/data_exploration/#the-basic-select-statement)
|
|
@ -0,0 +1,80 @@
|
|||
---
|
||||
title: group() function
|
||||
description: The group() function groups records based on their values for specific columns.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: group
|
||||
parent: Transformations
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `group()` function groups records based on their values for specific columns.
|
||||
It produces tables with new group keys based on provided properties.
|
||||
|
||||
_**Function type:** Transformation_
|
||||
|
||||
```js
|
||||
group(columns: ["host", "_measurement"], mode:"by")
|
||||
|
||||
// OR
|
||||
|
||||
group(columns: ["_time"], mode:"except")
|
||||
|
||||
// OR
|
||||
|
||||
group()
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### columns
|
||||
List of columns to use in the grouping operation.
|
||||
Defaults to `[]`.
|
||||
|
||||
_**Data type:** Array of strings_
|
||||
|
||||
### mode
|
||||
The mode used to group columns.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
The following options are available:
|
||||
|
||||
- by
|
||||
- except
|
||||
|
||||
Defaults to `"by"`.
|
||||
|
||||
#### by
|
||||
Groups records by columns defined in the [`columns`](#columns) parameter.
|
||||
|
||||
#### except
|
||||
Groups records by all columns **except** those defined in the [`columns`](#columns) parameter.
|
||||
|
||||
## Examples
|
||||
|
||||
###### Group by host and measurement
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: -30m)
|
||||
|> group(columns: ["host", "_measurement"])
|
||||
```
|
||||
|
||||
###### Group by everything except time
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: -30m)
|
||||
|> group(columns: ["_time"], mode: "except")
|
||||
```
|
||||
|
||||
###### Remove all grouping
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: -30m)
|
||||
|> group()
|
||||
```
|
||||
|
||||
<hr style="margin-top:4rem"/>
|
||||
|
||||
##### Related InfluxQL functions and statements:
|
||||
[GROUP BY](https://docs.influxdata.com/influxdb/latest/query_language/data_exploration/#the-group-by-clause) _(similar but different)_
|
|
@ -0,0 +1,78 @@
|
|||
---
|
||||
title: histogram() function
|
||||
description: The histogram() function approximates the cumulative distribution of a dataset by counting data frequencies for a list of bins.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: histogram
|
||||
parent: Transformations
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `histogram()` function approximates the cumulative distribution of a dataset by counting data frequencies for a list of bins.
|
||||
A bin is defined by an upper bound where all data points that are less than or equal to the bound are counted in the bin.
|
||||
The bin counts are cumulative.
|
||||
|
||||
Each input table is converted into a single output table representing a single histogram.
|
||||
The output table has a the same group key as the input table.
|
||||
Columns not part of the group key are removed and an upper bound column and a count column are added.
|
||||
|
||||
_**Function type:** Transformation_
|
||||
_**Output data type:** Object_
|
||||
|
||||
```js
|
||||
histogram(column: "_value", upperBoundColumn: "le", countColumn: "_value", bins: [50.0, 75.0, 90.0], normalize: false)
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### column
|
||||
The name of a column containing input data values.
|
||||
The column type must be float.
|
||||
Defaults to `"_value"`.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
### upperBoundColumn
|
||||
The name of the column in which to store the histogram's upper bounds.
|
||||
Defaults to `"le"`.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
### countColumn
|
||||
The name of the column in which to store the histogram counts.
|
||||
Defaults to `"_value"`.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
### bins
|
||||
A list of upper bounds to use when computing the histogram frequencies.
|
||||
Bins should contain a bin whose bound is the maximum value of the data set.
|
||||
This value can be set to positive infinity if no maximum is known.
|
||||
|
||||
_**Data type:** Array of floats_
|
||||
|
||||
#### Bin helper functions
|
||||
The following helper functions can be used to generated bins.
|
||||
|
||||
[linearBins()](/v2.0/reference/flux/functions/misc/linearbins)
|
||||
[logarithmicBins()](/v2.0/reference/flux/functions/misc/logarithmicbins)
|
||||
|
||||
### normalize
|
||||
When `true`, will convert the counts into frequency values between 0 and 1.
|
||||
Defaults to `false`.
|
||||
|
||||
_**Data type:** Boolean_
|
||||
|
||||
{{% note %}}
|
||||
Normalized histograms cannot be aggregated by summing their counts.
|
||||
{{% /note %}}
|
||||
|
||||
## Examples
|
||||
|
||||
##### Histogram with dynamically generated bins
|
||||
```js
|
||||
// Dynamically generate 10 bins from 0,10,20,...,100
|
||||
histogram(
|
||||
bins: linearBins(start:0.0, width:10.0, count:10)
|
||||
)
|
||||
```
|
|
@ -0,0 +1,40 @@
|
|||
---
|
||||
title: influxFieldsAsCols() function
|
||||
description: The influxFieldsAsCols() function is pivots a table and automatically aligns fields within each input table that have the same timestamp.
|
||||
aliases:
|
||||
- /v2.0/reference/flux/functions/inputs/fromrows
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: influxFieldsAsCols
|
||||
parent: Transformations
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `influxFieldsAsCols()` function is a special application of the `pivot()` function that
|
||||
automatically aligns fields within each input table that have the same timestamp.
|
||||
|
||||
_**Function type:** Transformation_
|
||||
|
||||
```js
|
||||
influxFieldsAsCols()
|
||||
```
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket:"telegraf/autogen")
|
||||
|> range(start: -1h)
|
||||
|> filter(fn: (r) => r._measurement == "cpu")
|
||||
|> influxFieldsAsCols()
|
||||
|> keep(columns: ["_time", "cpu", "usage_idle", "usage_user"])
|
||||
```
|
||||
|
||||
## Function definition
|
||||
```js
|
||||
influxFieldsAsCols = (tables=<-) =>
|
||||
tables
|
||||
|> pivot(
|
||||
rowKey:["_time"],
|
||||
columnKey: ["_field"],
|
||||
valueColumn: "_value"
|
||||
)
|
||||
```
|
|
@ -0,0 +1,133 @@
|
|||
---
|
||||
title: join() function
|
||||
description: The join() function merges two or more input streams whose values are equal on a set of common columns into a single output stream.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: join
|
||||
parent: Transformations
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `join()` function merges two or more input streams whose values are equal on
|
||||
a set of common columns into a single output stream.
|
||||
Null values are not considered equal when comparing column values.
|
||||
The resulting schema is the union of the input schemas.
|
||||
The resulting group key is the union of the input group keys.
|
||||
|
||||
_**Function type:** Transformation_
|
||||
_**Output data type:** Object_
|
||||
|
||||
```js
|
||||
join(tables: {key1: table1, key2: table2}, on: ["_time", "_field"], method: "inner")
|
||||
```
|
||||
|
||||
#### Output schema
|
||||
The column schema of the output stream is the union of the input schemas.
|
||||
It is also the same for the output group key.
|
||||
Columns are renamed using the pattern `<column>_<table>` to prevent ambiguity in joined tables.
|
||||
|
||||
##### Example:
|
||||
If you have two streams of data, **data_1** and **data_2**, with the following group keys:
|
||||
|
||||
**data_1**: `[_time, _field]`
|
||||
**data_2**: `[_time, _field]`
|
||||
|
||||
And join them with:
|
||||
|
||||
```js
|
||||
join(tables: {d1: data_1, d2: data_2}, on: ["_time"])
|
||||
```
|
||||
|
||||
The resulting group keys for all tables will be: `[_time, _field_d1, _field_d2]`
|
||||
|
||||
|
||||
## Parameters
|
||||
|
||||
### tables
|
||||
The map of streams to be joined. <span style="color:#FF8564; font-weight:700;">Required</span>.
|
||||
|
||||
_**Data type:** Object_
|
||||
|
||||
> `join()` currently only supports two input streams.
|
||||
|
||||
### on
|
||||
The list of columns on which to join. <span style="color:#FF8564; font-weight:700;">Required</span>.
|
||||
|
||||
_**Data type:** Array of strings_
|
||||
|
||||
### method
|
||||
The method used to join. Defaults to `"inner"`.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
###### Possible Values:
|
||||
- `inner`
|
||||
- `cross`
|
||||
- `left`
|
||||
- `right`
|
||||
- `full`
|
||||
|
||||
{{% note %}}
|
||||
The `on` parameter and the cross method are mutually exclusive.
|
||||
{{% /note %}}
|
||||
|
||||
## Examples
|
||||
|
||||
#### Example join with sample data
|
||||
|
||||
Given the following two streams of data:
|
||||
|
||||
##### SF_Temp**
|
||||
|
||||
| _time | _field | _value |
|
||||
| ------ |:------:| -------:|
|
||||
| 0001 | "temp" | 70 |
|
||||
| 0002 | "temp" | 75 |
|
||||
| 0003 | "temp" | 72 |
|
||||
|
||||
##### NY_Temp**
|
||||
|
||||
| _time | _field | _value |
|
||||
| ------ |:------:| -------:|
|
||||
| 0001 | "temp" | 55 |
|
||||
| 0002 | "temp" | 56 |
|
||||
| 0003 | "temp" | 55 |
|
||||
|
||||
And the following join query:
|
||||
|
||||
```js
|
||||
join(
|
||||
tables: {sf: SF_Temp, ny: NY_Temp},
|
||||
on: ["_time", "_field"]
|
||||
)
|
||||
```
|
||||
|
||||
The output will be:
|
||||
|
||||
| _time | _field | _value_ny | _value_sf |
|
||||
| ----- | ------ | ---------:| ---------:|
|
||||
| 0001 | "temp" | 55 | 70 |
|
||||
| 0002 | "temp" | 56 | 75 |
|
||||
| 0003 | "temp" | 55 | 72 |
|
||||
|
||||
#### Cross-measurement join
|
||||
```js
|
||||
data_1 = from(bucket:"telegraf/autogen")
|
||||
|> range(start:-15m)
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "cpu" and
|
||||
r._field == "usage_system"
|
||||
)
|
||||
|
||||
data_2 = from(bucket:"telegraf/autogen")
|
||||
|> range(start:-15m)
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "mem" and
|
||||
r._field == "used_percent"
|
||||
)
|
||||
|
||||
join(
|
||||
tables: {d1: data_1, d2: data_2},
|
||||
on: ["_time", "host"]
|
||||
)
|
||||
```
|
|
@ -0,0 +1,55 @@
|
|||
---
|
||||
title: keep() function
|
||||
description: The keep() function returns a table containing only the specified columns.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: keep
|
||||
parent: Transformations
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `keep()` function returns a table containing only the specified columns, ignoring all others.
|
||||
Only columns in the group key that are also specified in the `keep()` function will be kept in the resulting group key.
|
||||
_It is the inverse of [`drop`](/v2.0/reference/flux/functions/transformations/drop)._
|
||||
|
||||
_**Function type:** Transformation_
|
||||
_**Output data type:** Object_
|
||||
|
||||
```js
|
||||
keep(columns: ["col1", "col2"])
|
||||
|
||||
// OR
|
||||
|
||||
keep(fn: (column) => column =~ /inodes*/)
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### columns
|
||||
Columns that should be included in the resulting table.
|
||||
Cannot be used with `fn`.
|
||||
|
||||
_**Data type:** Array of strings_
|
||||
|
||||
### fn
|
||||
A predicate function which takes a column name as a parameter (`column`) and returns
|
||||
a boolean indicating whether or not the column should be included in the resulting table.
|
||||
Cannot be used with `columns`.
|
||||
|
||||
_**Data type:** Function_
|
||||
|
||||
## Examples
|
||||
|
||||
##### Keep a list of columns
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: -5m)
|
||||
|> keep(columns: ["_time", "_value"])
|
||||
```
|
||||
|
||||
##### Keep all columns matching a predicate
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: -5m)
|
||||
|> keep(fn: (column) => column =~ /inodes*/)
|
||||
```
|
|
@ -0,0 +1,57 @@
|
|||
---
|
||||
title: keys() function
|
||||
description: >
|
||||
The keys() function outputs the group key of input tables.
|
||||
For each input table, it outputs a table with the same group key columns, plus a
|
||||
_value column containing the labels of the input table's group key.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: keys
|
||||
parent: Transformations
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `keys()` function outputs the group key of input tables.
|
||||
For each input table, it outputs a table with the same group key columns, plus a
|
||||
`_value` column containing the labels of the input table's group key.
|
||||
Each row in an output table contains the group key value and the label of one column in the group key of the input table.
|
||||
Each output table has the same number of rows as the size of the group key of the input table.
|
||||
|
||||
_**Function type:** Transformation_
|
||||
|
||||
```js
|
||||
keys(column: "_value")
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### column
|
||||
The name of the output column in which to store the group key labels.
|
||||
Defaults to `"_value"`.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: -30m)
|
||||
|> keys(column: "keys")
|
||||
```
|
||||
|
||||
##### Return every possible key in a single table
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: -30m)
|
||||
|> keys()
|
||||
|> keep(columns: ["_value"])
|
||||
|> group()
|
||||
|> distinct()
|
||||
```
|
||||
|
||||
<hr style="margin-top:4rem"/>
|
||||
|
||||
##### Related InfluxQL functions and statements:
|
||||
[SHOW MEASUREMENTS](https://docs.influxdata.com/influxdb/latest/query_language/schema_exploration/#show-measurements)
|
||||
[SHOW FIELD KEYS](https://docs.influxdata.com/influxdb/latest/query_language/schema_exploration/#show-field-keys)
|
||||
[SHOW TAG KEYS](https://docs.influxdata.com/influxdb/latest/query_language/schema_exploration/#show-tag-keys)
|
||||
[SHOW SERIES](https://docs.influxdata.com/influxdb/latest/query_language/schema_exploration/#show-tag-keys)
|
|
@ -0,0 +1,75 @@
|
|||
---
|
||||
title: keyValues() function
|
||||
description: The keyValues() function returns a table with the input table's group key plus two columns, _key and _value, that correspond to unique column + value pairs from the input table.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: keyValues
|
||||
parent: Transformations
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `keyValues()` function returns a table with the input table's group key plus two columns,
|
||||
`_key` and `_value`, that correspond to unique column + value pairs from the input table.
|
||||
|
||||
_**Function type:** Transformation_
|
||||
_**Output data type:** Object_
|
||||
|
||||
```js
|
||||
keyValues(keyColumns: ["usage_idle", "usage_user"])
|
||||
|
||||
// OR
|
||||
|
||||
keyValues(fn: (schema) => schema.columns |> filter(fn: (r) => r.label =~ /usage_.*/))
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
{{% note %}}
|
||||
`keyColumns` and `fn` are mutually exclusive. Only one may be used at a time.
|
||||
{{% /note %}}
|
||||
|
||||
### keyColumns
|
||||
A list of columns from which values are extracted.
|
||||
All columns indicated must be of the same type.
|
||||
Each input table must have all of the columns listed by the `keyColumns` parameter.
|
||||
|
||||
_**Data type:** Array of strings_
|
||||
|
||||
### fn
|
||||
Function used to identify a set of columns.
|
||||
All columns indicated must be of the same type.
|
||||
|
||||
_**Data type:** Function_
|
||||
|
||||
## Additional requirements
|
||||
|
||||
- Only one of `keyColumns` or `fn` may be used in a single call.
|
||||
- All columns indicated must be of the same type.
|
||||
- Each input table must have all of the columns listed by the `keyColumns` parameter.
|
||||
|
||||
## Examples
|
||||
|
||||
##### Get key values from explicitly defined columns
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: -30m)
|
||||
|> filter(fn: (r) => r._measurement == "cpu")
|
||||
|> keyValues(keyColumns: ["usage_idle", "usage_user"])
|
||||
```
|
||||
|
||||
##### Get key values from columns matching a regular expression
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: -30m)
|
||||
|> filter(fn: (r) => r._measurement == "cpu")
|
||||
|> keyValues(fn: (schema) => schema.columns |> filter(fn: (r) => r.label =~ /usage_.*/))
|
||||
```
|
||||
|
||||
<hr style="margin-top:4rem"/>
|
||||
|
||||
##### Related InfluxQL functions and statements:
|
||||
[SHOW MEASUREMENTS](https://docs.influxdata.com/influxdb/latest/query_language/schema_exploration/#show-measurements)
|
||||
[SHOW FIELD KEYS](https://docs.influxdata.com/influxdb/latest/query_language/schema_exploration/#show-field-keys)
|
||||
[SHOW TAG KEYS](https://docs.influxdata.com/influxdb/latest/query_language/schema_exploration/#show-tag-keys)
|
||||
[SHOW TAG VALUES](https://docs.influxdata.com/influxdb/latest/query_language/schema_exploration/#show-tag-values)
|
||||
[SHOW SERIES](https://docs.influxdata.com/influxdb/latest/query_language/schema_exploration/#show-series)
|
|
@ -0,0 +1,46 @@
|
|||
---
|
||||
title: limit() function
|
||||
description: The limit() function limits the number of records in output tables to a fixed number (n).
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: limit
|
||||
parent: Transformations
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `limit()` function limits the number of records in output tables to a fixed number ([`n`](#n)).
|
||||
One output table is produced for each input table.
|
||||
Each output table contains the first `n` records after the first `offset` records of the input table.
|
||||
If the input table has less than `offset + n` records, all records except the first `offset` ones are output.
|
||||
|
||||
_**Function type:** Filter_
|
||||
_**Output data type:** Object_
|
||||
|
||||
```js
|
||||
limit(n:10, offset: 0)
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### n
|
||||
The maximum number of records to output.
|
||||
|
||||
_**Data type:** Integer_
|
||||
|
||||
### offset
|
||||
The number of records to skip per table before limiting to `n`.
|
||||
Defaults to `0`.
|
||||
|
||||
_**Data type:** Integer_
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket:"telegraf/autogen")
|
||||
|> range(start:-1h)
|
||||
|> limit(n:10, offset: 1)
|
||||
```
|
||||
|
||||
<hr style="margin-top:4rem"/>
|
||||
|
||||
##### Related InfluxQL functions and statements:
|
||||
[LIMIT](https://docs.influxdata.com/influxdb/latest/query_language/data_exploration/#the-limit-and-slimit-clauses)
|
|
@ -0,0 +1,72 @@
|
|||
---
|
||||
title: map() function
|
||||
description: The map() function applies a function to each record in the input tables.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: map
|
||||
parent: Transformations
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `map()` function applies a function to each record in the input tables.
|
||||
The modified records are assigned to new tables based on the group key of the input table.
|
||||
The output tables are the result of applying the map function to each record of the input tables.
|
||||
|
||||
When the output record contains a different value for the group key, the record is regrouped into the appropriate table.
|
||||
When the output record drops a column that was part of the group key, that column is removed from the group key.
|
||||
|
||||
_**Function type:** Transformation_
|
||||
_**Output data type:** Object_
|
||||
|
||||
```js
|
||||
map(fn: (r) => r._value * r._value), mergeKey: true)
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### fn
|
||||
A single argument function that to apply to each record.
|
||||
The return value must be an object.
|
||||
|
||||
_**Data type:** Function_
|
||||
|
||||
{{% note %}}
|
||||
Objects evaluated in `fn` functions are represented by `r`, short for "record" or "row".
|
||||
{{% /note %}}
|
||||
|
||||
### mergeKey
|
||||
Indicates if the record returned from `fn` should be merged with the group key.
|
||||
When merging, all columns on the group key will be added to the record giving precedence to any columns already present on the record.
|
||||
When not merging, only columns defined on the returned record will be present on the output records.
|
||||
Defaults to `true`.
|
||||
|
||||
_**Data type:** Boolean_
|
||||
|
||||
## Examples
|
||||
|
||||
###### Square the value of each record
|
||||
```js
|
||||
from(bucket:"telegraf/autogen")
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "cpu" and
|
||||
r._field == "usage_system" and
|
||||
r.cpu == "cpu-total"
|
||||
)
|
||||
|> range(start:-12h)
|
||||
|> map(fn: (r) => r._value * r._value)
|
||||
```
|
||||
|
||||
###### Create a new table with new format
|
||||
```js
|
||||
from(bucket:"telegraf/autogen")
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "cpu" and
|
||||
r._field == "usage_system"
|
||||
)
|
||||
|> range(start:-12h)
|
||||
// create a new table by copying each row into a new format
|
||||
|> map(fn: (r) => ({
|
||||
_time: r._time,
|
||||
app_server: r.host
|
||||
}))
|
||||
```
|
|
@ -0,0 +1,148 @@
|
|||
---
|
||||
title: pivot() function
|
||||
description: The pivot() function collects values stored vertically (column-wise) in a table and aligns them horizontally (row-wise) into logical sets.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: pivot
|
||||
parent: Transformations
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `pivot()` function collects values stored vertically (column-wise) in a table
|
||||
and aligns them horizontally (row-wise) into logical sets.
|
||||
|
||||
_**Function type:** Transformation_
|
||||
_**Output data type:** Object_
|
||||
|
||||
```js
|
||||
pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
|
||||
```
|
||||
|
||||
The group key of the resulting table is the same as the input tables, excluding columns found in the [`columnKey`](#columnkey) and [`valueColumn`](#valuecolumn) parameters.
|
||||
This is because these columns are not part of the resulting output table.
|
||||
|
||||
Every input row should have a 1:1 mapping to a particular row + column in the output table, determined by its values for the [`rowKey`](#rowkey) and [`columnKey`](#columnkey) parameters.
|
||||
In cases where more than one value is identified for the same row + column pair, the last value
|
||||
encountered in the set of table rows is used as the result.
|
||||
|
||||
Every input row should have a 1:1 mapping to a particular row/column pair in the output table,
|
||||
determined by its values for the `rowKey` and `columnKey`.
|
||||
In cases where more than one value is identified for the same row/column pair in the output,
|
||||
the last value encountered in the set of table rows is used as the result.
|
||||
|
||||
The output is constructed as follows:
|
||||
|
||||
- The set of columns for the new table is the `rowKey` unioned with the group key,
|
||||
but excluding the columns indicated by the `columnKey` and the `valueColumn`.
|
||||
- A new column is added to the set of columns for each unique value identified
|
||||
in the input by the `columnKey` parameter.
|
||||
- The label of a new column is the concatenation of the values of `columnKey` using `_` as a separator.
|
||||
If the value is `null`, `"null"` is used.
|
||||
- A new row is created for each unique value identified in the input by the `rowKey` parameter.
|
||||
- For each new row, values for group key columns stay the same, while values for new columns are
|
||||
determined from the input tables by the value in `valueColumn` at the row identified by the
|
||||
`rowKey` values and the new column's label.
|
||||
If no value is found, the value is set to `null`.
|
||||
|
||||
|
||||
## Parameters
|
||||
|
||||
### rowKey
|
||||
List of columns used to uniquely identify a row for the output.
|
||||
|
||||
_**Data type:** Array of strings_
|
||||
|
||||
### columnKey
|
||||
List of columns used to pivot values onto each row identified by the rowKey.
|
||||
|
||||
_**Data type:** Array of strings_
|
||||
|
||||
### valueColumn
|
||||
The single column that contains the value to be moved around the pivot.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
## Examples
|
||||
|
||||
### Align fields within each measurement that have the same timestamp
|
||||
|
||||
```js
|
||||
from(bucket:"test")
|
||||
|> range(start: 1970-01-01T00:00:00.000000000Z)
|
||||
|> pivot(
|
||||
rowKey:["_time"],
|
||||
columnKey: ["_field"],
|
||||
valueColumn: "_value"
|
||||
)
|
||||
```
|
||||
|
||||
###### Input
|
||||
| _time | _value | _measurement | _field |
|
||||
|:------------------------------:|:------:|:------------:|:------:|
|
||||
| 1970-01-01T00:00:00.000000001Z | 1.0 | "m1" | "f1" |
|
||||
| 1970-01-01T00:00:00.000000001Z | 2.0 | "m1" | "f2" |
|
||||
| 1970-01-01T00:00:00.000000001Z | null | "m1" | "f3" |
|
||||
| 1970-01-01T00:00:00.000000001Z | 3.0 | "m1" | null |
|
||||
| 1970-01-01T00:00:00.000000002Z | 4.0 | "m1" | "f1" |
|
||||
| 1970-01-01T00:00:00.000000002Z | 5.0 | "m1" | "f2" |
|
||||
| null | 6.0 | "m1" | "f2" |
|
||||
| 1970-01-01T00:00:00.000000002Z | null | "m1" | "f3" |
|
||||
| 1970-01-01T00:00:00.000000003Z | null | "m1" | "f1" |
|
||||
| 1970-01-01T00:00:00.000000003Z | 7.0 | "m1" | null |
|
||||
| 1970-01-01T00:00:00.000000004Z | 8.0 | "m1" | "f3" |
|
||||
|
||||
###### Output
|
||||
| _time | _measurement | f1 | f2 | f3 | null |
|
||||
|:------------------------------:|:------------:|:----:|:----:|:----:|:----:|
|
||||
| 1970-01-01T00:00:00.000000001Z | "m1" | 1.0 | 2.0 | null | 3.0 |
|
||||
| 1970-01-01T00:00:00.000000002Z | "m1" | 4.0 | 5.0 | null | null |
|
||||
| null | "m1" | null | 6.0 | null | null |
|
||||
| 1970-01-01T00:00:00.000000003Z | "m1" | null | null | null | 7.0 |
|
||||
| 1970-01-01T00:00:00.000000004Z | "m1" | null | null | 8.0 | null |
|
||||
|
||||
### Align fields and measurements that have the same timestamp
|
||||
|
||||
{{% note %}}
|
||||
Note the effects of:
|
||||
|
||||
- Having null values in some `columnKey` value;
|
||||
- Having more values for the same `rowKey` and `columnKey` value
|
||||
(the 11th row overrides the 10th, and so does the 15th with the 14th).
|
||||
{{% /note %}}
|
||||
|
||||
```js
|
||||
from(bucket:"test")
|
||||
|> range(start: 1970-01-01T00:00:00.000000000Z)
|
||||
|> pivot(
|
||||
rowKey:["_time"],
|
||||
columnKey: ["_measurement", "_field"],
|
||||
valueColumn: "_value"
|
||||
)
|
||||
```
|
||||
|
||||
###### Input
|
||||
| _time | _value | _measurement | _field |
|
||||
|:------------------------------:|:------:|:------------:|:------:|
|
||||
| 1970-01-01T00:00:00.000000001Z | 1.0 | "m1" | "f1" |
|
||||
| 1970-01-01T00:00:00.000000001Z | 2.0 | "m1" | "f2" |
|
||||
| 1970-01-01T00:00:00.000000001Z | 3.0 | null | "f3" |
|
||||
| 1970-01-01T00:00:00.000000001Z | 4.0 | null | null |
|
||||
| 1970-01-01T00:00:00.000000002Z | 5.0 | "m1" | "f1" |
|
||||
| 1970-01-01T00:00:00.000000002Z | 6.0 | "m1" | "f2" |
|
||||
| 1970-01-01T00:00:00.000000002Z | 7.0 | "m1" | "f3" |
|
||||
| 1970-01-01T00:00:00.000000002Z | 8.0 | null | null |
|
||||
| null | 9.0 | "m1" | "f3" |
|
||||
| 1970-01-01T00:00:00.000000003Z | 10.0 | "m1" | null |
|
||||
| 1970-01-01T00:00:00.000000003Z | 11.0 | "m1" | null |
|
||||
| 1970-01-01T00:00:00.000000003Z | 12.0 | "m1" | "f3" |
|
||||
| 1970-01-01T00:00:00.000000003Z | 13.0 | null | null |
|
||||
| null | 14.0 | "m1" | null |
|
||||
| null | 15.0 | "m1" | null |
|
||||
|
||||
###### Output
|
||||
| _time | m1_f1 | m1_f2 | null_f3 | null_null | m1_f3 | m1_null |
|
||||
|:------------------------------:|:-----:|:-----:|:---------:|:---------:|:-----:|:-------:|
|
||||
| 1970-01-01T00:00:00.000000001Z | 1.0 | 2.0 | 3.0 | 4.0 | null | null |
|
||||
| 1970-01-01T00:00:00.000000002Z | 5.0 | 6.0 | null | 8.0 | 7.0 | null |
|
||||
| null | null | null | null | null | 9.0 | 15.0 |
|
||||
| 1970-01-01T00:00:00.000000003Z | null | null | null | 13.0 | 12.0 | 11.0 |
|
|
@ -0,0 +1,70 @@
|
|||
---
|
||||
title: range() function
|
||||
description: The range() function filters records based on time bounds.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: range
|
||||
parent: Transformations
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `range()` function filters records based on time bounds.
|
||||
Each input table's records are filtered to contain only records that exist within the time bounds.
|
||||
Records with a `null` value for their time are filtered.
|
||||
Each input table's group key value is modified to fit within the time bounds.
|
||||
Tables where all records exists outside the time bounds are filtered entirely.
|
||||
|
||||
_**Function type:** Transformation_
|
||||
_**Output data type:* Object_
|
||||
|
||||
```js
|
||||
range(start: -15m, stop: now)
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### start
|
||||
Specifies the oldest time to be included in the results.
|
||||
|
||||
Relative start times are defined using negative durations.
|
||||
Negative durations are relative to now.
|
||||
Absolute start times are defined using timestamps.
|
||||
|
||||
_**Data type:** Duration or Timestamp_
|
||||
|
||||
### stop
|
||||
Specifies the exclusive newest time to be included in the results. Defaults to `now`.
|
||||
|
||||
Relative stop times are defined using negative durations.
|
||||
Negative durations are relative to now.
|
||||
Absolute stop times are defined using timestamps.
|
||||
|
||||
_**Data type:** Duration or Timestamp_
|
||||
|
||||
## Examples
|
||||
|
||||
###### Time range relative to now
|
||||
```js
|
||||
from(bucket:"telegraf/autogen")
|
||||
|> range(start:-12h)
|
||||
// ...
|
||||
```
|
||||
|
||||
###### Relative time range
|
||||
```js
|
||||
from(bucket:"telegraf/autogen")
|
||||
|> range(start:-12h, stop: -15m)
|
||||
// ...
|
||||
```
|
||||
|
||||
###### Absolute time range
|
||||
```js
|
||||
from(bucket:"telegraf/autogen")
|
||||
|> range(start:2018-05-22T23:30:00Z, stop: 2018-05-23T00:00:00Z)
|
||||
// ...
|
||||
```
|
||||
|
||||
<hr style="margin-top:4rem"/>
|
||||
|
||||
##### Related InfluxQL functions and statements:
|
||||
[WHERE](https://docs.influxdata.com/influxdb/latest/query_language/data_exploration/#the-where-clause)
|
|
@ -0,0 +1,57 @@
|
|||
---
|
||||
title: rename() function
|
||||
description: The rename() function renames specified columns in a table.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: rename
|
||||
parent: Transformations
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `rename()` function renames specified columns in a table.
|
||||
If a column is renamed and is part of the group key, the column name in the group key will be updated.
|
||||
|
||||
There are two variants:
|
||||
|
||||
- one which maps old column names to new column names
|
||||
- one which takes a mapping function.
|
||||
|
||||
_**Function type:** Transformation_
|
||||
|
||||
```js
|
||||
rename(columns: {host: "server", facility: "datacenter"})
|
||||
|
||||
// OR
|
||||
|
||||
rename(fn: (column) => "{column}_new")
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### columns
|
||||
A map of columns to rename and their corresponding new names.
|
||||
Cannot be used with `fn`.
|
||||
|
||||
_**Data type:** Object_
|
||||
|
||||
### fn
|
||||
A function mapping between old and new column names.
|
||||
Cannot be used with `columns`.
|
||||
|
||||
_**Data type:** Function_
|
||||
|
||||
## Examples
|
||||
|
||||
##### Rename a single column
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: -5m)
|
||||
|> rename(columns: {host: "server"})
|
||||
```
|
||||
|
||||
##### Rename all columns using a function
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: -5m)
|
||||
|> rename(fn: (column) => column + "_new")
|
||||
```
|
|
@ -0,0 +1,24 @@
|
|||
---
|
||||
title: Flux selector functions
|
||||
description: Flux selector functions return one or more records based on function logic.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
parent: Transformations
|
||||
name: Selectors
|
||||
weight: 1
|
||||
---
|
||||
|
||||
Flux selector functions return one or more records based on function logic.
|
||||
The output table is different than the input table, but individual row values are not.
|
||||
|
||||
The following selector functions are available:
|
||||
|
||||
{{< function-list category="Selectors" menu="v2_0_ref" >}}
|
||||
|
||||
|
||||
### Selectors and aggregates
|
||||
The following functions can be used as both selectors or aggregates, but they are
|
||||
categorized as aggregate functions in this documentation:
|
||||
|
||||
- [median](/v2.0/reference/flux/functions/transformations/aggregates/median)
|
||||
- [percentile](/v2.0/reference/flux/functions/transformations/aggregates/percentile)
|
|
@ -0,0 +1,60 @@
|
|||
---
|
||||
title: bottom() function
|
||||
description: The bottom() function sorts a table by columns and keeps only the bottom n records.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: bottom
|
||||
parent: Selectors
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `bottom()` function sorts a table by columns and keeps only the bottom `n` records.
|
||||
|
||||
_**Function type:** Selector_
|
||||
_**Output data type:** Object_
|
||||
|
||||
```js
|
||||
bottom(n:10, columns: ["_value"])
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### n
|
||||
Number of records to return.
|
||||
|
||||
_**Data type:** Integer_
|
||||
|
||||
### columns
|
||||
List of columns by which to sort.
|
||||
Sort precedence is determined by list order (left to right).
|
||||
Default is `["_value"]`.
|
||||
|
||||
_**Data type:** Array of strings_
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket:"telegraf/autogen")
|
||||
|> range(start:-1h)
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "mem" and
|
||||
r._field == "used_percent"
|
||||
)
|
||||
|> bottom(n:10)
|
||||
```
|
||||
|
||||
## Function definition
|
||||
```js
|
||||
// _sortLimit is a helper function, which sorts and limits a table.
|
||||
_sortLimit = (n, desc, columns=["_value"], tables=<-) =>
|
||||
tables
|
||||
|> sort(columns:columns, desc:desc)
|
||||
|> limit(n:n)
|
||||
|
||||
bottom = (n, columns=["_value"], tables=<-) =>
|
||||
_sortLimit(n:n, columns:columns, desc:false)
|
||||
```
|
||||
|
||||
<hr style="margin-top:4rem"/>
|
||||
|
||||
##### Related InfluxQL functions and statements:
|
||||
[BOTTOM()](https://docs.influxdata.com/influxdb/latest/query_language/functions/#bottom)
|
|
@ -0,0 +1,39 @@
|
|||
---
|
||||
title: distinct() function
|
||||
description: The distinct() function returns the unique values for a given column.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: distinct
|
||||
parent: Selectors
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `distinct()` function returns the unique values for a given column.
|
||||
`null` is considered its own distinct value if it is present.
|
||||
|
||||
_**Function type:** Selector_
|
||||
_**Output data type:** Object_
|
||||
|
||||
```js
|
||||
distinct(column: "host")
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### column
|
||||
Column on which to track unique values.
|
||||
|
||||
_**Data type:** string_
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: -5m)
|
||||
|> filter(fn: (r) => r._measurement == "cpu")
|
||||
|> distinct(column: "host")
|
||||
```
|
||||
|
||||
<hr style="margin-top:4rem"/>
|
||||
|
||||
##### Related InfluxQL functions and statements:
|
||||
[DISTINCT()](https://docs.influxdata.com/influxdb/latest/query_language/functions/#distinct)
|
|
@ -0,0 +1,34 @@
|
|||
---
|
||||
title: first() function
|
||||
description: The first() function selects the first non-null record from an input table.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: first
|
||||
parent: Selectors
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `first()` function selects the first non-null record from an input table.
|
||||
|
||||
_**Function type:** Selector_
|
||||
_**Output data type:** Object_
|
||||
|
||||
```js
|
||||
first()
|
||||
```
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket:"telegraf/autogen")
|
||||
|> range(start:-1h)
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "cpu" and
|
||||
r._field == "usage_system"
|
||||
)
|
||||
|> first()
|
||||
```
|
||||
|
||||
<hr style="margin-top:4rem"/>
|
||||
|
||||
##### Related InfluxQL functions and statements:
|
||||
[FIRST()](https://docs.influxdata.com/influxdb/latest/query_language/functions/#first)
|
|
@ -0,0 +1,82 @@
|
|||
---
|
||||
title: highestAverage() function
|
||||
description: The highestAverage() function returns the top 'n' records from all groups using the average of each group.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: highestAverage
|
||||
parent: Selectors
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `highestAverage()` function returns the top `n` records from all groups using the average of each group.
|
||||
|
||||
_**Function type:** Selector, Aggregate_
|
||||
|
||||
```js
|
||||
highestAverage(
|
||||
n:10,
|
||||
columns: ["_value"],
|
||||
groupColumns: []
|
||||
)
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### n
|
||||
Number of records to return.
|
||||
|
||||
_**Data type:** Integer_
|
||||
|
||||
### columns
|
||||
List of columns by which to sort.
|
||||
Sort precedence is determined by list order (left to right).
|
||||
Default is `["_value"]`.
|
||||
|
||||
_**Data type:** Array of strings_
|
||||
|
||||
### groupColumns
|
||||
The columns on which to group before performing the aggregation.
|
||||
Default is `[]`.
|
||||
|
||||
_**Data type:** Array of strings_
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket:"telegraf/autogen")
|
||||
|> range(start:-1h)
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "mem" and
|
||||
r._field == "used_percent"
|
||||
)
|
||||
|> highestAverage(n:10, groupColumns: ["host"])
|
||||
```
|
||||
|
||||
## Function definition
|
||||
```js
|
||||
// _sortLimit is a helper function, which sorts and limits a table.
|
||||
_sortLimit = (n, desc, columns=["_value"], tables=<-) =>
|
||||
tables
|
||||
|> sort(columns:columns, desc:desc)
|
||||
|> limit(n:n)
|
||||
|
||||
// _highestOrLowest is a helper function which reduces all groups into a single
|
||||
// group by specific tags and a reducer function. It then selects the highest or
|
||||
// lowest records based on the columns and the _sortLimit function.
|
||||
// The default reducer assumes no reducing needs to be performed.
|
||||
_highestOrLowest = (n, _sortLimit, reducer, columns=["_value"], groupColumns=[], tables=<-) =>
|
||||
tables
|
||||
|> group(columns:groupColumns)
|
||||
|> reducer()
|
||||
|> group(columns:[])
|
||||
|> _sortLimit(n:n, columns:columns)
|
||||
|
||||
highestAverage = (n, columns=["_value"], groupColumns=[], tables=<-) =>
|
||||
tables
|
||||
|> _highestOrLowest(
|
||||
n:n,
|
||||
columns:columns,
|
||||
groupColumns:groupColumns,
|
||||
reducer: (tables=<-) => tables |> mean(columns:[columns[0]]),
|
||||
_sortLimit: top,
|
||||
)
|
||||
```
|
|
@ -0,0 +1,82 @@
|
|||
---
|
||||
title: highestCurrent() function
|
||||
description: The highestCurrent() function returns the top 'n' records from all groups using the last value of each group.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: highestCurrent
|
||||
parent: Selectors
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `highestCurrent()` function returns the top `n` records from all groups using the last value of each group.
|
||||
|
||||
_**Function type:** Selector, Aggregate_
|
||||
|
||||
```js
|
||||
highestCurrent(
|
||||
n:10,
|
||||
columns: ["_value"],
|
||||
groupColumns: []
|
||||
)
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### n
|
||||
Number of records to return.
|
||||
|
||||
_**Data type:** Integer_
|
||||
|
||||
### columns
|
||||
List of columns by which to sort.
|
||||
Sort precedence is determined by list order (left to right).
|
||||
Default is `["_value"]`.
|
||||
|
||||
_**Data type:** Array of strings_
|
||||
|
||||
### groupColumns
|
||||
The columns on which to group before performing the aggregation.
|
||||
Default is `[]`.
|
||||
|
||||
_**Data type:** Array of strings_
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket:"telegraf/autogen")
|
||||
|> range(start:-1h)
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "mem" and
|
||||
r._field == "used_percent"
|
||||
)
|
||||
|> highestCurrent(n:10, groupColumns: ["host"])
|
||||
```
|
||||
|
||||
## Function definition
|
||||
```js
|
||||
// _sortLimit is a helper function, which sorts and limits a table.
|
||||
_sortLimit = (n, desc, columns=["_value"], tables=<-) =>
|
||||
tables
|
||||
|> sort(columns:columns, desc:desc)
|
||||
|> limit(n:n)
|
||||
|
||||
// _highestOrLowest is a helper function which reduces all groups into a single
|
||||
// group by specific tags and a reducer function. It then selects the highest or
|
||||
// lowest records based on the columns and the _sortLimit function.
|
||||
// The default reducer assumes no reducing needs to be performed.
|
||||
_highestOrLowest = (n, _sortLimit, reducer, columns=["_value"], groupColumns=[], tables=<-) =>
|
||||
tables
|
||||
|> group(columns:groupColumns)
|
||||
|> reducer()
|
||||
|> group(columns:[])
|
||||
|> _sortLimit(n:n, columns:columns)
|
||||
|
||||
highestCurrent = (n, columns=["_value"], groupColumns=[], tables=<-) =>
|
||||
tables
|
||||
|> _highestOrLowest(
|
||||
n:n,
|
||||
columns:columns,
|
||||
groupColumns:groupColumns,
|
||||
reducer: (tables=<-) => tables |> last(column:columns[0]),
|
||||
_sortLimit: top,
|
||||
)
|
||||
```
|
|
@ -0,0 +1,82 @@
|
|||
---
|
||||
title: highestMax() function
|
||||
description: The highestMax() function returns the top 'n' records from all groups using the maximum of each group.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: highestMax
|
||||
parent: Selectors
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `highestMax()` function returns the top `n` records from all groups using the maximum of each group.
|
||||
|
||||
_**Function type:** Selector, Aggregate_
|
||||
|
||||
```js
|
||||
highestMax(
|
||||
n:10,
|
||||
columns: ["_value"],
|
||||
groupColumns: []
|
||||
)
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### n
|
||||
Number of records to return.
|
||||
|
||||
_**Data type:** Integer_
|
||||
|
||||
### columns
|
||||
List of columns by which to sort.
|
||||
Sort precedence is determined by list order (left to right).
|
||||
Default is `["_value"]`.
|
||||
|
||||
_**Data type:** Array of strings_
|
||||
|
||||
### groupColumns
|
||||
The columns on which to group before performing the aggregation.
|
||||
Default is `[]`.
|
||||
|
||||
_**Data type:** Array of strings_
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket:"telegraf/autogen")
|
||||
|> range(start:-1h)
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "mem" and
|
||||
r._field == "used_percent"
|
||||
)
|
||||
|> highestMax(n:10, groupColumns: ["host"])
|
||||
```
|
||||
|
||||
## Function definition
|
||||
```js
|
||||
// _sortLimit is a helper function, which sorts and limits a table.
|
||||
_sortLimit = (n, desc, columns=["_value"], tables=<-) =>
|
||||
tables
|
||||
|> sort(columns:columns, desc:desc)
|
||||
|> limit(n:n)
|
||||
|
||||
// _highestOrLowest is a helper function which reduces all groups into a single
|
||||
// group by specific tags and a reducer function. It then selects the highest or
|
||||
// lowest records based on the columns and the _sortLimit function.
|
||||
// The default reducer assumes no reducing needs to be performed.
|
||||
_highestOrLowest = (n, _sortLimit, reducer, columns=["_value"], groupColumns=[], tables=<-) =>
|
||||
tables
|
||||
|> group(columns:groupColumns)
|
||||
|> reducer()
|
||||
|> group(columns:[])
|
||||
|> _sortLimit(n:n, columns:columns)
|
||||
|
||||
highestMax = (n, columns=["_value"], groupColumns=[], tables=<-) =>
|
||||
tables
|
||||
|> _highestOrLowest(
|
||||
n:n,
|
||||
columns:columns,
|
||||
groupColumns:groupColumns,
|
||||
reducer: (tables=<-) => tables |> max(column:columns[0]),
|
||||
_sortLimit: top
|
||||
)
|
||||
```
|
|
@ -0,0 +1,34 @@
|
|||
---
|
||||
title: last() function
|
||||
description: The last() function selects the last non-null record from an input table.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: last
|
||||
parent: Selectors
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `last()` function selects the last non-null record from an input table.
|
||||
|
||||
_**Function type:** Selector_
|
||||
_**Output data type:** Object_
|
||||
|
||||
```js
|
||||
last()
|
||||
```
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket:"telegraf/autogen")
|
||||
|> range(start:-1h)
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "cpu" and
|
||||
r._field == "usage_system"
|
||||
)
|
||||
|> last()
|
||||
```
|
||||
|
||||
<hr style="margin-top:4rem"/>
|
||||
|
||||
##### Related InfluxQL functions and statements:
|
||||
[LAST()](https://docs.influxdata.com/influxdb/latest/query_language/functions/#last)
|
|
@ -0,0 +1,83 @@
|
|||
---
|
||||
title: lowestAverage() function
|
||||
description: The lowestAverage() function returns the bottom 'n' records from all groups using the average of each group.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: lowestAverage
|
||||
parent: Selectors
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `lowestAverage()` function returns the bottom `n` records from all groups using the average of each group.
|
||||
|
||||
_**Function type:** Selector, Aggregate_
|
||||
|
||||
```js
|
||||
lowestAverage(
|
||||
n:10,
|
||||
columns: ["_value"],
|
||||
groupColumns: []
|
||||
)
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### n
|
||||
Number of records to return.
|
||||
|
||||
_**Data type:** Integer_
|
||||
|
||||
### columns
|
||||
List of columns by which to sort.
|
||||
Sort precedence is determined by list order (left to right).
|
||||
Default is `["_value"]`.
|
||||
|
||||
_**Data type:** Array of strings_
|
||||
|
||||
### groupColumns
|
||||
The columns on which to group before performing the aggregation.
|
||||
Default is `[]`.
|
||||
|
||||
_**Data type:** Array of strings_
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket:"telegraf/autogen")
|
||||
|> range(start:-1h)
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "mem" and
|
||||
r._field == "used_percent"
|
||||
)
|
||||
|> lowestAverage(n:10, groupColumns: ["host"])
|
||||
```
|
||||
|
||||
## Function definition
|
||||
```js
|
||||
// _sortLimit is a helper function, which sorts and limits a table.
|
||||
_sortLimit = (n, desc, columns=["_value"], tables=<-) =>
|
||||
tables
|
||||
|> sort(columns:columns, desc:desc)
|
||||
|> limit(n:n)
|
||||
|
||||
// _highestOrLowest is a helper function which reduces all groups into a single
|
||||
// group by specific tags and a reducer function. It then selects the highest or
|
||||
// lowest records based on the columns and the _sortLimit function.
|
||||
// The default reducer assumes no reducing needs to be performed.
|
||||
_highestOrLowest = (n, _sortLimit, reducer, columns=["_value"], groupColumns=[], tables=<-) =>
|
||||
tables
|
||||
|> group(columns:groupColumns)
|
||||
|> reducer()
|
||||
|> group(columns:[])
|
||||
|> _sortLimit(n:n, columns:columns)
|
||||
|
||||
lowestAverage = (n, columns=["_value"], groupColumns=[], tables=<-) =>
|
||||
tables
|
||||
|> _highestOrLowest(
|
||||
n:n,
|
||||
columns:columns,
|
||||
groupColumns:groupColumns,
|
||||
reducer: (tables=<-) => tables |> mean(columns:[columns[0]]),
|
||||
_sortLimit: bottom,
|
||||
)
|
||||
|
||||
```
|
|
@ -0,0 +1,82 @@
|
|||
---
|
||||
title: lowestCurrent() function
|
||||
description: The lowestCurrent() function returns the bottom 'n' records from all groups using the last value of each group.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: lowestCurrent
|
||||
parent: Selectors
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `lowestCurrent()` function returns the bottom `n` records from all groups using the last value of each group.
|
||||
|
||||
_**Function type:** Selector, Aggregate_
|
||||
|
||||
```js
|
||||
lowestCurrent(
|
||||
n:10,
|
||||
columns: ["_value"],
|
||||
groupColumns: []
|
||||
)
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### n
|
||||
Number of records to return.
|
||||
|
||||
_**Data type:** Integer_
|
||||
|
||||
### columns
|
||||
List of columns by which to sort.
|
||||
Sort precedence is determined by list order (left to right).
|
||||
Default is `["_value"]`.
|
||||
|
||||
_**Data type:** Array of strings_
|
||||
|
||||
### groupColumns
|
||||
The columns on which to group before performing the aggregation.
|
||||
Default is `[]`.
|
||||
|
||||
_**Data type:** Array of strings_
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket:"telegraf/autogen")
|
||||
|> range(start:-1h)
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "mem" and
|
||||
r._field == "used_percent"
|
||||
)
|
||||
|> lowestCurrent(n:10, groupColumns: ["host"])
|
||||
```
|
||||
|
||||
## Function definition
|
||||
```js
|
||||
// _sortLimit is a helper function, which sorts and limits a table.
|
||||
_sortLimit = (n, desc, columns=["_value"], tables=<-) =>
|
||||
tables
|
||||
|> sort(columns:columns, desc:desc)
|
||||
|> limit(n:n)
|
||||
|
||||
// _highestOrLowest is a helper function which reduces all groups into a single
|
||||
// group by specific tags and a reducer function. It then selects the highest or
|
||||
// lowest records based on the columns and the _sortLimit function.
|
||||
// The default reducer assumes no reducing needs to be performed.
|
||||
_highestOrLowest = (n, _sortLimit, reducer, columns=["_value"], groupColumns=[], tables=<-) =>
|
||||
tables
|
||||
|> group(columns:groupColumns)
|
||||
|> reducer()
|
||||
|> group(columns:[])
|
||||
|> _sortLimit(n:n, columns:columns)
|
||||
|
||||
lowestCurrent = (n, columns=["_value"], groupColumns=[], tables=<-) =>
|
||||
tables
|
||||
|> _highestOrLowest(
|
||||
n:n,
|
||||
columns:columns,
|
||||
groupColumns:groupColumns,
|
||||
reducer: (tables=<-) => tables |> last(column:columns[0]),
|
||||
_sortLimit: bottom,
|
||||
)
|
||||
```
|
|
@ -0,0 +1,83 @@
|
|||
---
|
||||
title: lowestMin() function
|
||||
description: The lowestMin() function returns the bottom 'n' records from all groups using the minimum of each group.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: lowestMin
|
||||
parent: Selectors
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `lowestMin()` function returns the bottom `n` records from all groups using the minimum of each group.
|
||||
|
||||
_**Function type:** Selector, Aggregate_
|
||||
|
||||
```js
|
||||
lowestMin(
|
||||
n:10,
|
||||
columns: ["_value"],
|
||||
groupColumns: []
|
||||
)
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### n
|
||||
Number of records to return.
|
||||
|
||||
_**Data type:** Integer_
|
||||
|
||||
### columns
|
||||
List of columns by which to sort.
|
||||
Sort precedence is determined by list order (left to right).
|
||||
Default is `["_value"]`.
|
||||
|
||||
_**Data type:** Array of strings_
|
||||
|
||||
### groupColumns
|
||||
The columns on which to group before performing the aggregation.
|
||||
Default is `[]`.
|
||||
|
||||
_**Data type:** Array of strings_
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket:"telegraf/autogen")
|
||||
|> range(start:-1h)
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "mem" and
|
||||
r._field == "used_percent"
|
||||
)
|
||||
|> lowestMin(n:10, groupColumns: ["host"])
|
||||
```
|
||||
|
||||
## Function definition
|
||||
```js
|
||||
// _sortLimit is a helper function, which sorts and limits a table.
|
||||
_sortLimit = (n, desc, columns=["_value"], tables=<-) =>
|
||||
tables
|
||||
|> sort(columns:columns, desc:desc)
|
||||
|> limit(n:n)
|
||||
|
||||
// _highestOrLowest is a helper function which reduces all groups into a single
|
||||
// group by specific tags and a reducer function. It then selects the highest or
|
||||
// lowest records based on the columns and the _sortLimit function.
|
||||
// The default reducer assumes no reducing needs to be performed.
|
||||
_highestOrLowest = (n, _sortLimit, reducer, columns=["_value"], groupColumns=[], tables=<-) =>
|
||||
tables
|
||||
|> group(columns:groupColumns)
|
||||
|> reducer()
|
||||
|> group(columns:[])
|
||||
|> _sortLimit(n:n, columns:columns)
|
||||
|
||||
lowestMin = (n, columns=["_value"], groupColumns=[], tables=<-) =>
|
||||
tables
|
||||
|> _highestOrLowest(
|
||||
n:n,
|
||||
columns:columns,
|
||||
groupColumns:groupColumns,
|
||||
// TODO(nathanielc): Once max/min support selecting based on multiple columns change this to pass all columns.
|
||||
reducer: (tables=<-) => tables |> min(column:columns[0]),
|
||||
_sortLimit: bottom,
|
||||
)
|
||||
```
|
|
@ -0,0 +1,34 @@
|
|||
---
|
||||
title: max() function
|
||||
description: The max() function selects record with the highest _value from the input table.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: max
|
||||
parent: Selectors
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `max()` function selects record with the highest `_value` from the input table.
|
||||
|
||||
_**Function type:** Selector_
|
||||
_**Output data type:** Object_
|
||||
|
||||
```js
|
||||
max()
|
||||
```
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket:"telegraf/autogen")
|
||||
|> range(start:-1h)
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "cpu" and
|
||||
r._field == "usage_system"
|
||||
)
|
||||
|> max()
|
||||
```
|
||||
|
||||
<hr style="margin-top:4rem"/>
|
||||
|
||||
##### Related InfluxQL functions and statements:
|
||||
[MAX()](https://docs.influxdata.com/influxdb/latest/query_language/functions/#max)
|
|
@ -0,0 +1,34 @@
|
|||
---
|
||||
title: min() function
|
||||
description: The min() function selects record with the lowest _value from the input table.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: min
|
||||
parent: Selectors
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `min()` function selects record with the lowest `_value` from the input table.
|
||||
|
||||
_**Function type:** Selector_
|
||||
_**Output data type:** Object_
|
||||
|
||||
```js
|
||||
min()
|
||||
```
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket:"telegraf/autogen")
|
||||
|> range(start:-1h)
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "cpu" and
|
||||
r._field == "usage_system"
|
||||
)
|
||||
|> min()
|
||||
```
|
||||
|
||||
<hr style="margin-top:4rem"/>
|
||||
|
||||
##### Related InfluxQL functions and statements:
|
||||
[MIN()](https://docs.influxdata.com/influxdb/latest/query_language/functions/#min)
|
|
@ -0,0 +1,49 @@
|
|||
---
|
||||
title: sample() function
|
||||
description: The sample() function selects a subset of the records from the input table.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: sample
|
||||
parent: Selectors
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `sample()` function selects a subset of the records from the input table.
|
||||
|
||||
_**Function type:** Selector_
|
||||
_**Output data type:** Object_
|
||||
|
||||
```js
|
||||
sample(n:5, pos: -1)
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### n
|
||||
Sample every Nth element.
|
||||
|
||||
_**Data type:** Integer_
|
||||
|
||||
### pos
|
||||
The position offset from the start of results where sampling begins.
|
||||
`pos` must be less than `n`.
|
||||
If `pos` is less than 0, a random offset is used.
|
||||
Defaults to `-1` (random offset).
|
||||
|
||||
_**Data type:** Integer_
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket:"telegraf/autogen")
|
||||
|> range(start:-1d)
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "cpu" and
|
||||
r._field == "usage_system"
|
||||
)
|
||||
|> sample(n: 5, pos: 1)
|
||||
```
|
||||
|
||||
<hr style="margin-top:4rem"/>
|
||||
|
||||
##### Related InfluxQL functions and statements:
|
||||
[SAMPLE()](https://docs.influxdata.com/influxdb/latest/query_language/functions/#sample)
|
|
@ -0,0 +1,54 @@
|
|||
---
|
||||
title: top() function
|
||||
description: The top() function sorts a table by columns and keeps only the top n records.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: top
|
||||
parent: Selectors
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `top()` function sorts a table by columns and keeps only the top `n` records.
|
||||
|
||||
_**Function type:** Selector_
|
||||
_**Output data type:** Object_
|
||||
|
||||
```js
|
||||
top(n:10, columns: ["_value"])
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### n
|
||||
Number of records to return.
|
||||
|
||||
_**Data type:** Integer_
|
||||
|
||||
### columns
|
||||
List of columns by which to sort.
|
||||
Sort precedence is determined by list order (left to right).
|
||||
Default is `["_value"]`.
|
||||
|
||||
_**Data type:** Array of strings_
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket:"telegraf/autogen")
|
||||
|> range(start:-1h)
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "mem" and
|
||||
r._field == "used_percent"
|
||||
)
|
||||
|> top(n:10)
|
||||
```
|
||||
|
||||
## Function definition
|
||||
```js
|
||||
// _sortLimit is a helper function, which sorts and limits a table.
|
||||
_sortLimit = (n, desc, columns=["_value"], tables=<-) =>
|
||||
tables
|
||||
|> sort(columns:columns, desc:desc)
|
||||
|> limit(n:n)
|
||||
|
||||
top = (n, columns=["_value"], tables=<-) => _sortLimit(n:n, columns:columns, desc:true)
|
||||
```
|
|
@ -0,0 +1,34 @@
|
|||
---
|
||||
title: unique() function
|
||||
description: The unique() function returns all records containing unique values in a specified column.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: unique
|
||||
parent: Selectors
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `unique()` function returns all records containing unique values in a specified column.
|
||||
|
||||
_**Function type:** Selector_
|
||||
_**Output data type:** Object_
|
||||
|
||||
```js
|
||||
unique(column: "_value")
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### column
|
||||
The column searched for unique values.
|
||||
Defaults to `"_value"`.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from("telegraf/autogen")
|
||||
|> range(start: -15m)
|
||||
|> filter(fn: (r) => r._measurement == "syslog")
|
||||
|> unique(column: "message")
|
||||
```
|
|
@ -0,0 +1,38 @@
|
|||
---
|
||||
title: set() function
|
||||
description: The set() function assigns a static value to each record in the input table.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: set
|
||||
parent: Transformations
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `set()` function assigns a static value to each record in the input table.
|
||||
The key may modify an existing column or add a new column to the tables.
|
||||
If the modified column is part of the group key, the output tables are regrouped as needed.
|
||||
|
||||
_**Function type:** Transformation_
|
||||
_**Output data type:** Object_
|
||||
|
||||
```js
|
||||
set(key: "myKey",value: "myValue")
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### key
|
||||
The label of the column to modify or set.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
### value
|
||||
The string value to set.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> set(key: "host", value: "prod-node-1")
|
||||
```
|
|
@ -0,0 +1,48 @@
|
|||
---
|
||||
title: shift() function
|
||||
description: The shift() function adds a fixed duration to time columns.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: shift
|
||||
parent: Transformations
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `shift()` function adds a fixed duration to time columns.
|
||||
The output table schema is the same as the input table.
|
||||
If the time is `null`, the time will continue to be `null`.
|
||||
|
||||
_**Function type:** Transformation_
|
||||
_**Output data type:** Object_
|
||||
|
||||
```js
|
||||
shift(shift: 10h, columns: ["_start", "_stop", "_time"])
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### shift
|
||||
The amount of time to add to each time value. The shift may be a negative duration.
|
||||
|
||||
_**Data type:** Duration_
|
||||
|
||||
### columns
|
||||
The list of all columns to be shifted. Defaults to `["_start", "_stop", "_time"]`.
|
||||
|
||||
_**Data type:** Array of strings_
|
||||
|
||||
## Examples
|
||||
|
||||
###### Shift forward in time
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: -5m)
|
||||
|> shift(shift: 12h)
|
||||
```
|
||||
|
||||
###### Shift backward in time
|
||||
```js
|
||||
from(bucket: "telegraf/autogen")
|
||||
|> range(start: -5m)
|
||||
|> shift(shift: -12h)
|
||||
```
|
|
@ -0,0 +1,51 @@
|
|||
---
|
||||
title: sort() function
|
||||
description: The sort() function orders the records within each table.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: sort
|
||||
parent: Transformations
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `sort()` function orders the records within each table.
|
||||
One output table is produced for each input table.
|
||||
The output tables will have the same schema as their corresponding input tables.
|
||||
|
||||
_**Function type:** Transformation_
|
||||
_**Output data type:** Object_
|
||||
|
||||
#### Sorting with null values
|
||||
When sorting, `null` values will always be first.
|
||||
When `desc: false`, nulls are less than every other value.
|
||||
When `desc: true`, nulls are greater than every value.
|
||||
|
||||
```js
|
||||
sort(columns: ["_value"], desc: false)
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### columns
|
||||
List of columns by which to sort.
|
||||
Sort precedence is determined by list order (left to right).
|
||||
Default is `["_value"]`.
|
||||
|
||||
_**Data type:** Array of strings_
|
||||
|
||||
### desc
|
||||
Sort results in descending order.
|
||||
Default is `false`.
|
||||
|
||||
_**Data type:** Boolean_
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket:"telegraf/autogen")
|
||||
|> range(start:-12h)
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "system" and
|
||||
r._field == "uptime"
|
||||
)
|
||||
|> sort(columns:["region", "host", "_value"])
|
||||
```
|
|
@ -0,0 +1,51 @@
|
|||
---
|
||||
title: stateCount() function
|
||||
description: The stateCount() function computes the number of consecutive records in a given state.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: stateCount
|
||||
parent: Transformations
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `stateCount()` function computes the number of consecutive records in a given state.
|
||||
The state is defined via the function `fn`.
|
||||
For each consecutive point that evaluates as `true`, the state count will be incremented.
|
||||
When a point evaluates as `false`, the state count is reset.
|
||||
The state count is added as an additional column to each record.
|
||||
|
||||
_**Function type:** Transformation_
|
||||
_**Output data type:** Integer_
|
||||
|
||||
```js
|
||||
stateCount(fn: (r) => r._field == "state", column: "stateCount")
|
||||
```
|
||||
|
||||
_If the expression generates an error during evaluation, the point is discarded
|
||||
and does not affect the state count._
|
||||
|
||||
## Parameters
|
||||
|
||||
### fn
|
||||
A single argument function that evaluates true or false to identify the state of the record.
|
||||
Records are passed to the function.
|
||||
Those that evaluate to `true` increment the state count.
|
||||
Those that evaluate to `false` reset the state count.
|
||||
|
||||
_**Data type:** Function_
|
||||
|
||||
### column
|
||||
The name of the column added to each record that contains the incremented state count.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from("monitor/autogen")
|
||||
|> range(start: -1h)
|
||||
|> filter(fn: (r) => r._measurement == "http")
|
||||
|> stateCount(
|
||||
fn: (r) => r.http_response_code == "500",
|
||||
column: "server_error_count"
|
||||
)
|
||||
```
|
|
@ -0,0 +1,63 @@
|
|||
---
|
||||
title: stateDuration() function
|
||||
description: The stateDuration() function computes the duration of a given state.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: stateDuration
|
||||
parent: Transformations
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `stateDuration()` function computes the duration of a given state.
|
||||
The state is defined via the function `fn`.
|
||||
For each consecutive point for that evaluates as `true`, the state duration will be
|
||||
incremented by the duration between points.
|
||||
When a point evaluates as `false`, the state duration is reset.
|
||||
The state duration is added as an additional column to each record.
|
||||
|
||||
_**Function type:** Transformation_
|
||||
_**Output data type:** Duration_
|
||||
|
||||
{{% note %}}
|
||||
As the first point in the given state has no previous point, its
|
||||
state duration will be 0.
|
||||
{{% /note %}}
|
||||
|
||||
```js
|
||||
stateDuration(fn: (r) => r._measurement == "state", column: "stateDuration", unit: 1s)
|
||||
```
|
||||
|
||||
_If the expression generates an error during evaluation, the point is discarded,
|
||||
and does not affect the state duration._
|
||||
|
||||
## Parameters
|
||||
|
||||
### fn
|
||||
A single argument function that evaluates true or false to identify the state of the record.
|
||||
Records are passed to the function.
|
||||
Those that evaluate to `true` increment the state duration.
|
||||
Those that evaluate to `false` reset the state duration.
|
||||
|
||||
_**Data type:** Function_
|
||||
|
||||
### column
|
||||
The name of the column added to each record that contains the state duration.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
### unit
|
||||
The unit of time in which the state duration is incremented.
|
||||
For example: `1s`, `1m`, `1h`, etc.
|
||||
|
||||
_**Data type:** Duration_
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from("monitor/autogen")
|
||||
|> range(start: -1h)
|
||||
|> filter(fn: (r) => r._measurement == "http")
|
||||
|> stateDuration(
|
||||
fn: (r) => r.http_response_code == "500",
|
||||
column: "server_error_duration"
|
||||
)
|
||||
```
|
|
@ -0,0 +1,14 @@
|
|||
---
|
||||
title: Flux type conversion functions
|
||||
description: Flux type conversion functions convert columns of the input table into a specific data type.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
parent: Transformations
|
||||
name: Type conversions
|
||||
weight: 1
|
||||
---
|
||||
|
||||
Flux type conversion functions convert columns of the input table into a specific data type.
|
||||
The following type conversion functions are available:
|
||||
|
||||
{{< function-list category="Type conversions" menu="v2_0_ref" >}}
|
|
@ -0,0 +1,35 @@
|
|||
---
|
||||
title: toBool() function
|
||||
description: The toBool() function converts a value to a boolean.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: toBool
|
||||
parent: Type conversions
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `toBool()` function converts a value to a boolean.
|
||||
|
||||
_**Function type:** Type conversion_
|
||||
_**Output data type:** Boolean_
|
||||
|
||||
```js
|
||||
toBool()
|
||||
```
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket: "telegraf")
|
||||
|> filter(fn:(r) =>
|
||||
r._measurement == "mem" and
|
||||
r._field == "used"
|
||||
)
|
||||
|> toBool()
|
||||
```
|
||||
|
||||
## Function definition
|
||||
```js
|
||||
toBool = (tables=<-) =>
|
||||
tables
|
||||
|> map(fn:(r) => bool(v: r._value))
|
||||
```
|
|
@ -0,0 +1,35 @@
|
|||
---
|
||||
title: toDuration() function
|
||||
description: The toDuration() function converts a value to a duration.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: toDuration
|
||||
parent: Type conversions
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `toDuration()` function converts a value to a duration.
|
||||
|
||||
_**Function type:** Type conversion_
|
||||
_**Output data type:** Duration_
|
||||
|
||||
```js
|
||||
toDuration()
|
||||
```
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket: "telegraf")
|
||||
|> filter(fn:(r) =>
|
||||
r._measurement == "mem" and
|
||||
r._field == "used"
|
||||
)
|
||||
|> toDuration()
|
||||
```
|
||||
|
||||
## Function definition
|
||||
```js
|
||||
toDuration = (tables=<-) =>
|
||||
tables
|
||||
|> map(fn:(r) => duration(v: r._value))
|
||||
```
|
|
@ -0,0 +1,35 @@
|
|||
---
|
||||
title: toFloat() function
|
||||
description: The toFloat() function converts a value to a float.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: toFloat
|
||||
parent: Type conversions
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `toFloat()` function converts a value to a float.
|
||||
|
||||
_**Function type:** Type conversion_
|
||||
_**Output data type:** Float_
|
||||
|
||||
```js
|
||||
toFloat()
|
||||
```
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket: "telegraf")
|
||||
|> filter(fn:(r) =>
|
||||
r._measurement == "mem" and
|
||||
r._field == "used"
|
||||
)
|
||||
|> toFloat()
|
||||
```
|
||||
|
||||
## Function definition
|
||||
```js
|
||||
toFloat = (tables=<-) =>
|
||||
tables
|
||||
|> map(fn:(r) => float(v: r._value))
|
||||
```
|
|
@ -0,0 +1,35 @@
|
|||
---
|
||||
title: toInt() function
|
||||
description: The toInt() function converts a value to an integer.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: toInt
|
||||
parent: Type conversions
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `toInt()` function converts a value to an integer.
|
||||
|
||||
_**Function type:** Type conversion_
|
||||
_**Output data type:** Integer_
|
||||
|
||||
```js
|
||||
toInt()
|
||||
```
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket: "telegraf")
|
||||
|> filter(fn:(r) =>
|
||||
r._measurement == "mem" and
|
||||
r._field == "used"
|
||||
)
|
||||
|> toInt()
|
||||
```
|
||||
|
||||
## Function definition
|
||||
```js
|
||||
toInt = (tables=<-) =>
|
||||
tables
|
||||
|> map(fn:(r) => int(v: r._value))
|
||||
```
|
|
@ -0,0 +1,35 @@
|
|||
---
|
||||
title: toString() function
|
||||
description: The toString() function converts a value to a string.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: toString
|
||||
parent: Type conversions
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `toString()` function converts a value to a string.
|
||||
|
||||
_**Function type:** Type conversion_
|
||||
_**Output data type:** String_
|
||||
|
||||
```js
|
||||
toString()
|
||||
```
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket: "telegraf")
|
||||
|> filter(fn:(r) =>
|
||||
r._measurement == "mem" and
|
||||
r._field == "used"
|
||||
)
|
||||
|> toString()
|
||||
```
|
||||
|
||||
## Function definition
|
||||
```js
|
||||
toString = (tables=<-) =>
|
||||
tables
|
||||
|> map(fn:(r) => string(v: r._value))
|
||||
```
|
|
@ -0,0 +1,35 @@
|
|||
---
|
||||
title: toTime() function
|
||||
description: The toTime() function converts a value to a time.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: toTime
|
||||
parent: Type conversions
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `toTime()` function converts a value to a time.
|
||||
|
||||
_**Function type:** Type conversion_
|
||||
_**Output data type:** Time_
|
||||
|
||||
```js
|
||||
toTime()
|
||||
```
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket: "telegraf")
|
||||
|> filter(fn:(r) =>
|
||||
r._measurement == "mem" and
|
||||
r._field == "used"
|
||||
)
|
||||
|> toTime()
|
||||
```
|
||||
|
||||
## Function definition
|
||||
```js
|
||||
toTime = (tables=<-) =>
|
||||
tables
|
||||
|> map(fn:(r) => time(v:r._value))
|
||||
```
|
|
@ -0,0 +1,35 @@
|
|||
---
|
||||
title: toUInt() function
|
||||
description: The toUInt() function converts a value to an uinteger.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: toUInt
|
||||
parent: Type conversions
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `toUInt()` function converts a value to an UInteger.
|
||||
|
||||
_**Function type:** Type conversion_
|
||||
_**Output data type:** UInteger_
|
||||
|
||||
```js
|
||||
toUInt()
|
||||
```
|
||||
|
||||
## Examples
|
||||
```js
|
||||
from(bucket: "telegraf")
|
||||
|> filter(fn:(r) =>
|
||||
r._measurement == "mem" and
|
||||
r._field == "used"
|
||||
)
|
||||
|> toUInt()
|
||||
```
|
||||
|
||||
## Function definition
|
||||
```js
|
||||
toUInt = (tables=<-) =>
|
||||
tables
|
||||
|> map(fn:(r) => uint(v:r._value))
|
||||
```
|
|
@ -0,0 +1,52 @@
|
|||
---
|
||||
title: union() function
|
||||
description: The union() function concatenates two or more input streams into a single output stream.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: union
|
||||
parent: Transformations
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `union()` function concatenates two or more input streams into a single output stream.
|
||||
In tables that have identical schemas and group keys, contents of the tables will be concatenated in the output stream.
|
||||
The output schemas of the `union()` function is the union of all input schemas.
|
||||
|
||||
`union()` does not preserve the sort order of the rows within tables.
|
||||
A sort operation may be added if a specific sort order is needed.
|
||||
|
||||
_**Function type:** Transformation_
|
||||
_**Output data type:** Object_
|
||||
|
||||
```js
|
||||
union(tables: ["table1", "table2"])
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### tables
|
||||
Specifies the streams to union together.
|
||||
There must be at least two streams.
|
||||
|
||||
_**Data type:** Array of streams_
|
||||
|
||||
## Examples
|
||||
```js
|
||||
left = from(bucket: "test")
|
||||
|> range(start: 2018-05-22T19:53:00Z, stop: 2018-05-22T19:53:50Z)
|
||||
|> filter(fn: (r) =>
|
||||
r._field == "usage_guest" or
|
||||
r._field == "usage_guest_nice"
|
||||
)
|
||||
|> drop(columns: ["_start", "_stop"])
|
||||
|
||||
right = from(bucket: "test")
|
||||
|> range(start: 2018-05-22T19:53:50Z, stop: 2018-05-22T19:54:20Z)
|
||||
|> filter(fn: (r) =>
|
||||
r._field == "usage_guest" or
|
||||
r._field == "usage_idle"
|
||||
)
|
||||
|> drop(columns: ["_start", "_stop"])
|
||||
|
||||
union(tables: [left, right])
|
||||
```
|
|
@ -0,0 +1,118 @@
|
|||
---
|
||||
title: window() function
|
||||
description: The window() function groups records based on a time value.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: window
|
||||
parent: Transformations
|
||||
weight: 1
|
||||
---
|
||||
|
||||
The `window()` function groups records based on a time value.
|
||||
New columns are added to uniquely identify each window.
|
||||
Those columns are added to the group key of the output tables.
|
||||
|
||||
A single input record will be placed into zero or more output tables, depending on the specific windowing function.
|
||||
|
||||
_**Function type:** Transformation_
|
||||
_**Output data type:** Object_
|
||||
|
||||
```js
|
||||
window(
|
||||
every: 5m,
|
||||
period: 5m,
|
||||
start: 12h,
|
||||
timeColumn: "_time",
|
||||
startColumn: "_start",
|
||||
stopColumn: "_stop"
|
||||
)
|
||||
|
||||
// OR
|
||||
|
||||
window(
|
||||
intervals: intervals(every: 5m, period: 5m, offset: 12h),
|
||||
timeColumn: "_time",
|
||||
startColumn: "_start",
|
||||
stopColumn: "_stop"
|
||||
)
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
{{% note %}}
|
||||
`every`,`period` or `intervals` is required.
|
||||
{{% /note %}}
|
||||
|
||||
### every
|
||||
Duration of time between windows.
|
||||
Defaults to `period` value.
|
||||
|
||||
_**Data type:** Duration_
|
||||
|
||||
### period
|
||||
Duration of the window.
|
||||
Period is the length of each interval.
|
||||
It can be negative, indicating the start and stop boundaries are reversed.
|
||||
Defaults to `every` value.
|
||||
|
||||
_**Data type:** Duration_
|
||||
|
||||
### start
|
||||
The start window time relative to the [`location`](/v2.0/reference/flux/language/options/#location) offset.
|
||||
It can be negative, indicating that the start goes backwards in time.
|
||||
The default aligns the window boundaries with `now`.
|
||||
|
||||
_**Data type:** Duration_
|
||||
|
||||
### intervals
|
||||
A function that returns an interval generator, a set of intervals used as windows.
|
||||
|
||||
_**Data type:** Function_
|
||||
|
||||
###### Example interval generator function
|
||||
```js
|
||||
intervals(every:1d, period:8h, offset:9h)
|
||||
```
|
||||
|
||||
> When `intervals` is used, `every`, `period`, and `start` cannot be used or need to be set to 0.
|
||||
|
||||
### timeColumn
|
||||
The column containing time.
|
||||
Defaults to `"_time"`.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
### startColumn
|
||||
The column containing the window start time.
|
||||
Defaults to `"_start"`.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
### stopColumn
|
||||
The column containing the window stop time.
|
||||
Defaults to `"_stop"`.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
## Examples
|
||||
|
||||
#### Window data into 10 minute intervals
|
||||
```js
|
||||
from(bucket:"telegraf/autogen")
|
||||
|> range(start:-12h)
|
||||
|> window(every:10m)
|
||||
// ...
|
||||
```
|
||||
|
||||
#### Window data using intervals function
|
||||
The following windows data into 8 hour intervals starting at 9AM every day.
|
||||
```js
|
||||
from(bucket:"telegraf/autogen")
|
||||
|> range(start:-12h)
|
||||
|> window(intervals: intervals(every:1d, period:8h, offset:9h))
|
||||
```
|
||||
|
||||
<hr style="margin-top:4rem"/>
|
||||
|
||||
##### Related InfluxQL functions and statements:
|
||||
[GROUP BY time()](https://docs.influxdata.com/influxdb/latest/query_language/data_exploration/#the-group-by-clause)
|
|
@ -13,8 +13,8 @@ menu:
|
|||
Flux contains many preassigned values.
|
||||
These preassigned values are defined in the source files for the various built-in packages.
|
||||
|
||||
## [System built-ins](/flux/v0.x/language/built-ins/system-built-ins)
|
||||
## [System built-ins](/v2.0/reference/flux/language/built-ins/system-built-ins)
|
||||
When a built-in value is not expressible in Flux, its value may be defined by the hosting environment.
|
||||
|
||||
## [Time constants](/flux/v0.x/language/built-ins/time-constants)
|
||||
## [Time constants](/v2.0/reference/flux/language/built-ins/time-constants)
|
||||
When a built-in value is not expressible in Flux, its value may be defined by the hosting environment.
|
||||
|
|
|
@ -5,7 +5,7 @@ description: >
|
|||
A package consists of one or more source files.
|
||||
Each source file is parsed individually and composed into a single package.
|
||||
aliases:
|
||||
- /flux/v0.x/language/programs
|
||||
- /v2.0/reference/flux/language/programs
|
||||
menu:
|
||||
v2_0_ref:
|
||||
parent: Flux language specification
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
{{ $category := (.Get "category") }}
|
||||
{{ $menu := (.Get "menu")}}
|
||||
<ul>
|
||||
{{ range (index .Site.Menus $menu) }}
|
||||
{{ if .HasChildren}}
|
||||
{{ range .Children }}
|
||||
{{ if eq .Parent $category }}
|
||||
{{ if not .HasChildren }}
|
||||
<li><a href="{{ .URL }}">{{ .Name }}</a></li>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ if .HasChildren}}
|
||||
{{ range .Children }}
|
||||
{{ if eq .Parent $category }}
|
||||
{{ if not .HasChildren }}
|
||||
<li><a href="{{ .URL }}">{{ .Name }}</a></li>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ if .HasChildren}}
|
||||
{{ range .Children }}
|
||||
{{ if eq .Parent $category }}
|
||||
{{ if not .HasChildren }}
|
||||
<li><a href="{{ .URL }}">{{ .Name }}</a></li>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
</ul>
|
Loading…
Reference in New Issue