Merge pull request #387 from influxdata/flux-0.38

Flux 0.38
pull/391/head
Scott Anderson 2019-08-13 10:44:17 -06:00 committed by GitHub
commit 280a2efe76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 727 additions and 70 deletions

View File

@ -10,7 +10,8 @@ menu:
weight: 501 weight: 501
--- ---
The `aggregateWindow()` function applies an aggregate function to fixed windows of time. The `aggregateWindow()` function applies an aggregate or selector function
(any function with a `column` parameter) to fixed windows of time.
_**Function type:** Aggregate_ _**Function type:** Aggregate_
@ -25,7 +26,7 @@ aggregateWindow(
) )
``` ```
As data is windowed into separate tables and aggregated, the `_time` column is dropped from each group key. As data is windowed into separate tables and processed, the `_time` column is dropped from each group key.
This function copies the timestamp from a remaining column into the `_time` column. This function copies the timestamp from a remaining column into the `_time` column.
View the [function definition](#function-definition). View the [function definition](#function-definition).
@ -42,7 +43,7 @@ The [aggregate function](/v2.0/reference/flux/functions/built-in/transformations
_**Data type:** Function_ _**Data type:** Function_
{{% note %}} {{% note %}}
Only aggregate functions with a `column` parameter (singular) work with `aggregateWindow()`. Only aggregate and selector functions with a `column` parameter (singular) work with `aggregateWindow()`.
{{% /note %}} {{% /note %}}
### column ### column
@ -84,10 +85,10 @@ from(bucket: "example-bucket")
fn: mean fn: mean
) )
``` ```
###### Specifying parameters of the aggregate function ###### Specify parameters of the aggregate function
To use `aggregateWindow()` aggregate functions that don't provide defaults for required parameters, To use functions that don't provide defaults for required parameters with `aggregateWindow()`,
for the `fn` parameter, define an anonymous function with `columns` and `tables` parameters define an anonymous function with `column` and `tables` parameters that pipe-forward
that pipe-forwards tables into the aggregate function with all required parameters defined: tables into the aggregate or selector function with all required parameters defined:
```js ```js
from(bucket: "example-bucket") from(bucket: "example-bucket")

View File

@ -17,7 +17,11 @@ _**Function type:** Aggregate_
_**Output data type:** Float_ _**Output data type:** Float_
```js ```js
difference(nonNegative: false, column: "_value") difference(
nonNegative: false,
column: "_value",
keepFirst: false
)
``` ```
## Parameters ## Parameters
@ -34,6 +38,13 @@ Defaults to `"_value"`.
_**Data type:** String_ _**Data type:** String_
### keepFirst
Indicates the first row should be kept.
If `true`, the difference will be `null`.
Defaults to `false`.
_**Data type:** Boolean_
## Subtraction rules for numeric types ## Subtraction rules for numeric types
- The difference between two non-null values is their algebraic difference; - The difference between two non-null values is their algebraic difference;
or `null`, if the result is negative and `nonNegative: true`; or `null`, if the result is negative and `nonNegative: true`;
@ -90,6 +101,20 @@ from(bucket: "example-bucket")
| 0004 | 6 | tv | | 0004 | 6 | tv |
| 0005 | null | tv | | 0005 | null | tv |
#### With keepFirst set to true
```js
|> difference(nonNegative: false, keepfirst: true):
```
###### Output table
| _time | _value | tag |
|:-----:|:------:|:---:|
| 0001 | null | tv |
| 0002 | null | tv |
| 0003 | -2 | tv |
| 0004 | 6 | tv |
| 0005 | null | tv |
<hr style="margin-top:4rem"/> <hr style="margin-top:4rem"/>
##### Related InfluxQL functions and statements: ##### Related InfluxQL functions and statements:

View File

@ -0,0 +1,63 @@
---
title: doubleEMA() function
description: >
The `doubleEMA()` function calculates the exponential moving average of values
grouped into `n` number of points, giving more weight to recent data at double
the rate of `exponentialMovingAverage()`.
menu:
v2_0_ref:
name: doubleEMA
parent: built-in-aggregates
weight: 501
related:
- /v2.0/reference/flux/functions/built-in/transformations/aggregates/movingaverage/
- /v2.0/reference/flux/functions/built-in/transformations/aggregates/tripleema/
- /v2.0/reference/flux/functions/built-in/transformations/aggregates/timedmovingaverage/
- /v2.0/reference/flux/functions/built-in/transformations/aggregates/exponentialmovingaverage/
- https://docs.influxdata.com/influxdb/v1.7/query_language/functions/#double-exponential-moving-average, InfluxQL DOUBLE_EXPONENTIAL_MOVING_AVERAGE()
---
The `doubleEMA()` function calculates the exponential moving average of values in
the `_value` column grouped into `n` number of points, giving more weight to recent
data at double the rate of [`exponentialMovingAverage()`](/v2.0/reference/flux/functions/built-in/transformations/aggregates/exponentialmovingaverage/).
_**Function type:** Aggregate_
```js
doubleEMA(n: 5)
```
##### Double exponential moving average rules
- A double exponential moving average is defined as `doubleEMA = 2 * EMA_N - EMA of EMA_N`.
- `EMA` is an exponential moving average.
- `N = n` is the period used to calculate the EMA.
- A true double exponential moving average requires at least `2 * n - 1` values.
If not enough values exist to calculate the double EMA, it returns a `NaN` value.
- `doubleEMA()` inherits all [exponential moving average rules](/v2.0/reference/flux/functions/built-in/transformations/aggregates/exponentialmovingaverage/#exponential-moving-average-rules).
## Parameters
### n
The number of points to average.
_**Data type:** Integer_
## Examples
#### Calculate a five point double exponential moving average
```js
from(bucket: "example-bucket"):
|> range(start: -12h)
|> doubleEMA(n: 5)
```
## Function definition
```js
doubleEMA = (n, tables=<-) =>
tables
|> exponentialMovingAverage(n:n)
|> duplicate(column:"_value", as:"ema")
|> exponentialMovingAverage(n:n)
|> map(fn: (r) => ({r with _value: 2.0 * r.ema - r._value}))
|> drop(columns: ["ema"])
```

View File

@ -1,8 +1,8 @@
--- ---
title: exponentialMovingAverage() function title: exponentialMovingAverage() function
description: > description: >
The `exponentialMovingAverage()` function calculates the exponential moving average The `exponentialMovingAverage()` function calculates the exponential moving average of values
of values grouped into `n` number of points, giving more weight to recent data. in the `_value` column grouped into `n` number of points, giving more weight to recent data.
menu: menu:
v2_0_ref: v2_0_ref:
name: exponentialMovingAverage name: exponentialMovingAverage
@ -11,22 +11,21 @@ weight: 501
related: related:
- /v2.0/reference/flux/functions/built-in/transformations/aggregates/movingaverage/ - /v2.0/reference/flux/functions/built-in/transformations/aggregates/movingaverage/
- /v2.0/reference/flux/functions/built-in/transformations/aggregates/timedmovingaverage/ - /v2.0/reference/flux/functions/built-in/transformations/aggregates/timedmovingaverage/
- /v2.0/reference/flux/functions/built-in/transformations/aggregates/doubleema/
- /v2.0/reference/flux/functions/built-in/transformations/aggregates/tripleema/
- https://docs.influxdata.com/influxdb/v1.7/query_language/functions/#exponential-moving-average, InfluxQL EXPONENTIAL_MOVING_AVERAGE() - https://docs.influxdata.com/influxdb/v1.7/query_language/functions/#exponential-moving-average, InfluxQL EXPONENTIAL_MOVING_AVERAGE()
--- ---
The `exponentialMovingAverage()` function calculates the exponential moving average The `exponentialMovingAverage()` function calculates the exponential moving average of values
of values grouped into `n` number of points, giving more weight to recent data. in the `_value` column grouped into `n` number of points, giving more weight to recent data.
_**Function type:** Aggregate_ _**Function type:** Aggregate_
```js ```js
exponentialMovingAverage( exponentialMovingAverage(n: 5)
n: 5,
columns: ["_value"]
)
``` ```
##### Exponential moving average rules: ##### Exponential moving average rules
- The first value of an exponential moving average over `n` values is the - The first value of an exponential moving average over `n` values is the
algebraic mean of `n` values. algebraic mean of `n` values.
- Subsequent values are calculated as `y(t) = x(t) * k + y(t-1) * (1 - k)`, where: - Subsequent values are calculated as `y(t) = x(t) * k + y(t-1) * (1 - k)`, where:
@ -43,11 +42,6 @@ The number of points to average.
_**Data type:** Integer_ _**Data type:** Integer_
### columns
Columns to operate on. _Defaults to `["_value"]`_.
_**Data type:** Array of Strings_
## Examples ## Examples
#### Calculate a five point exponential moving average #### Calculate a five point exponential moving average
@ -60,23 +54,20 @@ from(bucket: "example-bucket"):
#### Table transformation with a two point exponential moving average #### Table transformation with a two point exponential moving average
###### Input table: ###### Input table:
| _time | A | B | C | tag | | _time | tag | _value |
|:-----:|:----:|:----:|:----:|:---:| |:-----:|:---:|:------:|
| 0001 | 2 | null | 2 | tv | | 0001 | tv | null |
| 0002 | null | 10 | 4 | tv | | 0002 | tv | 10 |
| 0003 | 8 | 20 | 5 | tv | | 0003 | tv | 20 |
###### Query: ###### Query:
```js ```js
// ... // ...
|> exponentialMovingAverage( |> exponentialMovingAverage(n: 2)
n: 2,
columns: ["A", "B", "C"]
)
``` ```
###### Output table: ###### Output table:
| _time | A | B | C | tag | | _time | tag | _value |
|:-----:|:----:|:----:|:----:|:---:| |:-----:|:---:|:------:|
| 0002 | 2 | 10 | 3 | tv | | 0002 | tv | 10 |
| 0003 | 6 | 16.67| 4.33 | tv | | 0003 | tv | 16.67 |

View File

@ -0,0 +1,114 @@
---
title: holtWinters() function
description: >
The `holtWinters()` function applies the Holt-Winters forecasting method to input tables.
aliases:
- /v2.0/reference/flux/functions/transformations/aggregates/holtwinters
menu:
v2_0_ref:
name: holtWinters
parent: built-in-aggregates
weight: 501
related:
- https://docs.influxdata.com/influxdb/latest/query_language/functions/#holt-winters, InfluxQL HOLT_WINTERS()
---
The `holtWinters()` function applies the Holt-Winters forecasting method to input tables.
_**Function type:** Aggregate_
_**Output data type:** Float_
```js
holtWinters(
n: 10,
seasonality: 4,
interval: 30d,
withFit: false,
timeColumn: "_time",
column: "_value",
)
```
The Holt-Winters method predicts [`n`](#n) seasonally-adjusted values for the
specified [`column`](#column) at the specified [`interval`](#interval).
For example, if `interval` is `6m` and `n` is `3`, results include three predicted
values six minutes apart.
#### Seasonality
[`seasonality`](#seasonality) delimits the length of a seasonal pattern according to `interval`.
If your `interval` is `2m` and `seasonality` is `4`, then the seasonal pattern occurs every
eight minutes or every four data points.
If data doesn't have a seasonal pattern, set `seasonality` to `0`.
#### Space values evenly in time
`holtWinters()` expects values evenly spaced in time.
To ensure `holtWinters()` values are spaced evenly in time, the following rules apply:
- Data is grouped into time-based "buckets" determined by the `interval`.
- If a bucket includes many values, the first value is used.
- If a bucket includes no values, a missing value (`null`) is added for that bucket.
By default, `holtWinters()` uses the first value in each time bucket to run the Holt-Winters calculation.
To specify other values to use in the calculation, use:
- [`window()`](/v2.0/reference/flux/functions/built-in/transformations/window/)
with [selectors](/v2.0/reference/flux/functions/built-in/transformations/selectors/)
or [aggregates](/v2.0/reference/flux/functions/built-in/transformations/aggregates/)
- [`aggregateWindow()`](/v2.0/reference/flux/functions/built-in/transformations/aggregates/aggregatewindow)
#### Fitted model
The `holtWinters()` function applies the [Nelder-Mead optimization](https://en.wikipedia.org/wiki/Nelder%E2%80%93Mead_method)
to include "fitted" data points in results when [`withFit`](#withfit) is set to `true`.
#### Null timestamps
`holtWinters()` discards rows with `null` timestamps before running the Holt-Winters calculation.
#### Null values
`holtWinters()` treats `null` values as missing data points and includes them in the Holt-Winters calculation.
## Parameters
### n
The number of values to predict.
_**Data type: Integer**_
### seasonality
The number of points in a season.
Defaults to `0`.
_**Data type: Integer**_
### interval
The interval between two data points.
_**Data type: Duration**_
### withFit
Return [fitted data](#fitted-model) in results.
Defaults to `false`.
_**Data type: Boolean**_
### timeColumn
The time column to use.
Defaults to `"_time"`.
_**Data type: String**_
### column
The column to operate on.
Defaults to `"_value"`.
_**Data type: String**_
## Examples
##### Use aggregateWindow to prepare data for holtWinters
```js
from(bucket: "example-bucket")
|> range(start: -7y)
|> filter(fn: (r) => r._field == "water_level")
|> aggregateWindow(every: 379m, fn: first).
|> holtWinters(n: 10, seasonality: 4, interval: 379m)
```

View File

@ -10,21 +10,21 @@ weight: 501
related: related:
- /v2.0/reference/flux/functions/built-in/transformations/aggregates/timedmovingaverage/ - /v2.0/reference/flux/functions/built-in/transformations/aggregates/timedmovingaverage/
- /v2.0/reference/flux/functions/built-in/transformations/aggregates/exponentialmovingaverage/ - /v2.0/reference/flux/functions/built-in/transformations/aggregates/exponentialmovingaverage/
- /v2.0/reference/flux/functions/built-in/transformations/aggregates/doubleema/
- /v2.0/reference/flux/functions/built-in/transformations/aggregates/tripleema/
- https://docs.influxdata.com/influxdb/latest/query_language/functions/#moving-average, InfluxQL MOVING_AVERAGE() - https://docs.influxdata.com/influxdb/latest/query_language/functions/#moving-average, InfluxQL MOVING_AVERAGE()
--- ---
The `movingAverage()` function calculates the mean of values grouped into `n` number of points. The `movingAverage()` function calculates the mean of values in the `_values` column
grouped into `n` number of points.
_**Function type:** Aggregate_ _**Function type:** Aggregate_
```js ```js
movingAverage( movingAverage(n: 5)
n: 5,
columns: ["_value"]
)
``` ```
##### Moving average rules: ##### Moving average rules
- The average over a period populated by `n` values is equal to their algebraic mean. - The average over a period populated by `n` values is equal to their algebraic mean.
- The average over a period populated by only `null` values is `null`. - The average over a period populated by only `null` values is `null`.
- Moving averages skip `null` values. - Moving averages skip `null` values.
@ -38,11 +38,6 @@ The number of points to average.
_**Data type:** Integer_ _**Data type:** Integer_
### columns
Columns to operate on. _Defaults to `["_value"]`_.
_**Data type:** Array of Strings_
## Examples ## Examples
#### Calculate a five point moving average #### Calculate a five point moving average
@ -52,36 +47,23 @@ from(bucket: "example-bucket"):
|> movingAverage(n: 5) |> movingAverage(n: 5)
``` ```
#### Calculate a ten point moving average
```js
movingAverage = (every, period, column="_value", tables=<-) =>
tables
|> window(every: every, period: period)
|> mean(column: column)
|> duplicate(column: "_stop", as: "_time")
|> window(every: inf)
```
#### Table transformation with a two point moving average #### Table transformation with a two point moving average
###### Input table: ###### Input table:
| _time | A | B | C | D | tag | | _time | tag | _value |
|:-----:|:----:|:----:|:----:|:----:|:---:| |:-----:|:---:|:------:|
| 0001 | null | 1 | 2 | null | tv | | 0001 | tv | null |
| 0002 | 6 | 2 | null | null | tv | | 0002 | tv | 6 |
| 0003 | 4 | null | 4 | 4 | tv | | 0003 | tv | 4 |
###### Query: ###### Query:
```js ```js
// ... // ...
|> movingAverage( |> movingAverage(n: 2 )
n: 2,
columns: ["A", "B", "C", "D"]
)
``` ```
###### Output table: ###### Output table:
| _time | A | B | C | D | tag | | _time | tag | _value |
|:-----:|:----:|:----:|:----:|:----:|:---:| |:-----:|:---:|:------:|
| 0002 | 6 | 1.5 | 2 | null | tv | | 0002 | tv | 6 |
| 0003 | 5 | 2 | 4 | 4 | tv | | 0003 | tv | 5 |

View File

@ -0,0 +1,103 @@
---
title: relativeStrengthIndex() function
description: >
The `relativeStrengthIndex()` function measures the relative speed and change of
values in an input table.
menu:
v2_0_ref:
name: relativeStrengthIndex
parent: built-in-aggregates
weight: 501
related:
- /v2.0/reference/flux/functions/built-in/transformations/aggregates/movingaverage/
- /v2.0/reference/flux/functions/built-in/transformations/aggregates/timedmovingaverage/
- /v2.0/reference/flux/functions/built-in/transformations/aggregates/exponentialmovingaverage/
- https://docs.influxdata.com/influxdb/v1.7/query_language/functions/#relative-strength-index, InfluxQL RELATIVE_STRENGTH_INDEX()
---
The `relativeStrengthIndex()` function measures the relative speed and change of
values in an input table.
_**Function type:** Aggregate_
```js
relativeStrengthIndex(
n: 5,
columns: ["_value"]
)
```
##### Relative strength index rules
- The general equation for calculating a relative strength index (RSI) is
`RSI = 100 - (100 / (1 + (AVG GAIN / AVG LOSS)))`.
- For the first value of the RSI, `AVG GAIN` and `AVG LOSS` are averages of the `n` period.
- For subsequent calculations:
- `AVG GAIN` = `((PREVIOUS AVG GAIN) * (n - 1)) / n`
- `AVG LOSS` = `((PREVIOUS AVG LOSS) * (n - 1)) / n`
- `relativeStrengthIndex()` ignores `null` values.
## Parameters
### n
The number of values to use to calculate the RSI.
_**Data type:** Integer_
### columns
Columns to operate on. _Defaults to `["_value"]`_.
_**Data type:** Array of Strings_
## Examples
#### Calculate a five point relative strength index
```js
from(bucket: "example-bucket"):
|> range(start: -12h)
|> relativeStrengthIndex(n: 5)
```
#### Table transformation with a ten point RSI
###### Input table:
| _time | A | B | tag |
|:-----:|:----:|:----:|:---:|
| 0001 | 1 | 1 | tv |
| 0002 | 2 | 2 | tv |
| 0003 | 3 | 3 | tv |
| 0004 | 4 | 4 | tv |
| 0005 | 5 | 5 | tv |
| 0006 | 6 | 6 | tv |
| 0007 | 7 | 7 | tv |
| 0008 | 8 | 8 | tv |
| 0009 | 9 | 9 | tv |
| 0010 | 10 | 10 | tv |
| 0011 | 11 | 11 | tv |
| 0012 | 12 | 12 | tv |
| 0013 | 13 | 13 | tv |
| 0014 | 14 | 14 | tv |
| 0015 | 15 | 15 | tv |
| 0016 | 16 | 16 | tv |
| 0017 | 17 | null | tv |
| 0018 | 18 | 17 | tv |
###### Query:
```js
// ...
|> relativeStrengthIndex(
n: 10,
columns: ["A", "B"]
)
```
###### Output table:
| _time | A | B | tag |
|:-----:|:----:|:----:|:---:|
| 0011 | 100 | 100 | tv |
| 0012 | 100 | 100 | tv |
| 0013 | 100 | 100 | tv |
| 0014 | 100 | 100 | tv |
| 0015 | 100 | 100 | tv |
| 0016 | 90 | 90 | tv |
| 0017 | 81 | 90 | tv |
| 0018 | 72.9 | 81 | tv |

View File

@ -11,6 +11,8 @@ weight: 501
related: related:
- /v2.0/reference/flux/functions/built-in/transformations/aggregates/movingaverage/ - /v2.0/reference/flux/functions/built-in/transformations/aggregates/movingaverage/
- /v2.0/reference/flux/functions/built-in/transformations/aggregates/exponentialmovingaverage/ - /v2.0/reference/flux/functions/built-in/transformations/aggregates/exponentialmovingaverage/
- /v2.0/reference/flux/functions/built-in/transformations/aggregates/doubleema/
- /v2.0/reference/flux/functions/built-in/transformations/aggregates/tripleema/
- https://docs.influxdata.com/influxdb/latest/query_language/functions/#moving-average, InfluxQL MOVING_AVERAGE() - https://docs.influxdata.com/influxdb/latest/query_language/functions/#moving-average, InfluxQL MOVING_AVERAGE()
--- ---

View File

@ -0,0 +1,68 @@
---
title: tripleEMA() function
description: >
The `tripleEMA()` function calculates the exponential moving average of values
grouped into `n` number of points, giving more weight to recent data with less lag
than `exponentialMovingAverage()` and `doubleEMA()`.
menu:
v2_0_ref:
name: tripleEMA
parent: built-in-aggregates
weight: 501
related:
- /v2.0/reference/flux/functions/built-in/transformations/aggregates/movingaverage/
- /v2.0/reference/flux/functions/built-in/transformations/aggregates/doubleema/
- /v2.0/reference/flux/functions/built-in/transformations/aggregates/timedmovingaverage/
- /v2.0/reference/flux/functions/built-in/transformations/aggregates/exponentialmovingaverage/
- https://docs.influxdata.com/influxdb/v1.7/query_language/functions/#triple-exponential-moving-average, InfluxQL TRIPLE_EXPONENTIAL_MOVING_AVERAGE()
---
The `tripleEMA()` function calculates the exponential moving average of values in
the `_value` column grouped into `n` number of points, giving more weight to recent
data with less lag than
[`exponentialMovingAverage()`](/v2.0/reference/flux/functions/built-in/transformations/aggregates/exponentialmovingaverage/)
and [`doubleEMA()`](/v2.0/reference/flux/functions/built-in/transformations/aggregates/doubleema/).
_**Function type:** Aggregate_
```js
tripleEMA(n: 5)
```
##### Triple exponential moving average rules
- A triple exponential moving average is defined as `tripleEMA = (3 * EMA_1) - (3 * EMA_2) + EMA_3`.
- `EMA_1` is the exponential moving average of the original data.
- `EMA_2` is the exponential moving average of `EMA_1`.
- `EMA_3` is the exponential moving average of `EMA_2`.
- A true triple exponential moving average requires at least requires at least `3 * n - 2` values.
If not enough values exist to calculate the triple EMA, it returns a `NaN` value.
- `tripleEMA()` inherits all [exponential moving average rules](/v2.0/reference/flux/functions/built-in/transformations/aggregates/exponentialmovingaverage/#exponential-moving-average-rules).
## Parameters
### n
The number of points to average.
_**Data type:** Integer_
## Examples
#### Calculate a five point triple exponential moving average
```js
from(bucket: "example-bucket"):
|> range(start: -12h)
|> tripleEMA(n: 5)
```
## Function definition
```js
tripleEMA = (n, tables=<-) =>
tables
|> exponentialMovingAverage(n:n)
|> duplicate(column:"_value", as:"ema1")
|> exponentialMovingAverage(n:n)
|> duplicate(column:"_value", as:"ema2")
|> exponentialMovingAverage(n:n)
|> map(fn: (r) => ({r with _value: 3.0 * r.ema1 - 3.0 * r.ema2 + r._value}))
|> drop(columns: ["ema1", "ema2"])
```

View File

@ -0,0 +1,31 @@
---
title: date.microsecond() function
description: >
The `date.microsecond()` function returns the microsecond of a specified time.
Results range from `[0-999999]`.
menu:
v2_0_ref:
name: date.microsecond
parent: Date
weight: 301
---
The `date.microsecond()` function returns the microsecond of a specified time.
Results range from `[0-999999]`.
_**Function type:** Transformation_
```js
import "date"
date.microsecond(t: 2019-07-17T12:05:21.012934584Z)
// Returns 12934
```
## Parameters
### t
The time to operate on.
_**Data type:** Time_

View File

@ -0,0 +1,31 @@
---
title: date.millisecond() function
description: >
The `date.millisecond()` function returns the millisecond of a specified time.
Results range from `[0-999999]`.
menu:
v2_0_ref:
name: date.millisecond
parent: Date
weight: 301
---
The `date.millisecond()` function returns the millisecond of a specified time.
Results range from `[0-999]`.
_**Function type:** Transformation_
```js
import "date"
date.millisecond(t: 2019-07-17T12:05:21.012934584Z)
// Returns 12
```
## Parameters
### t
The time to operate on.
_**Data type:** Time_

View File

@ -0,0 +1,31 @@
---
title: date.nanosecond() function
description: >
The `date.nanosecond()` function returns the nanosecond of a specified time.
Results range from `[0-999999999]`.
menu:
v2_0_ref:
name: date.nanosecond
parent: Date
weight: 301
---
The `date.nanosecond()` function returns the nanosecond of a specified time.
Results range from `[0-999999999]`.
_**Function type:** Transformation_
```js
import "date"
date.nanosecond(t: 2019-07-17T12:05:21.012934584Z)
// Returns 12934584
```
## Parameters
### t
The time to operate on.
_**Data type:** Time_

View File

@ -0,0 +1,31 @@
---
title: date.quarter() function
description: >
The `date.quarter()` function returns the quarter of the year for a specified time.
Results range from `[1-4]`.
menu:
v2_0_ref:
name: date.quarter
parent: Date
weight: 301
---
The `date.quarter()` function returns the quarter of the year for a specified time.
Results range from `[1-4]`.
_**Function type:** Transformation_
```js
import "date"
date.quarter(t: 2019-07-17T12:05:21.012Z)
// Returns 3
```
## Parameters
### t
The time to operate on.
_**Data type:** Time_

View File

@ -0,0 +1,57 @@
---
title: date.truncate() function
description: >
The `date.truncate()` function truncates a time to a specified unit.
menu:
v2_0_ref:
name: date.truncate
parent: Date
weight: 301
---
The `date.truncate()` function truncates a time to a specified unit.
_**Function type:** Transformation_
```js
import "date"
date.truncate(
t: 2019-07-17T12:05:21.012Z
unit: 1s
)
// Returns 2019-07-17T12:05:21.000000000Z
```
## Parameters
### t
The time to operate on.
_**Data type:** Time_
### unit
The unit time to truncate to.
_**Data type:** Duration_
{{% note %}}
Only use `1` and the unit of time to specify the `unit`.
For example: `1s`, `1m`, `1h`.
{{% /note %}}
## Examples
```js
import "date"
date.truncate(t: "2019-06-03T13:59:01.000000000Z", unit: 1s)
// Returns 2019-06-03T13:59:01.000000000Z
date.truncate(t: "2019-06-03T13:59:01.000000000Z", unit: 1m)
// Returns 2019-06-03T13:59:00.000000000Z
date.truncate(t: "2019-06-03T13:59:01.000000000Z", unit: 1h)
// Returns 2019-06-03T13:00:00.000000000Z
```

View File

@ -0,0 +1,31 @@
---
title: date.week() function
description: >
The `date.week()` function returns the ISO week of the year for a specified time.
Results range from `[1-53]`.
menu:
v2_0_ref:
name: date.week
parent: Date
weight: 301
---
The `date.week()` function returns the ISO week of the year for a specified time.
Results range from `[1-53]`.
_**Function type:** Transformation_
```js
import "date"
date.week(t: 2019-07-17T12:05:21.012Z)
// Returns 29
```
## Parameters
### t
The time to operate on.
_**Data type:** Time_

View File

@ -0,0 +1,30 @@
---
title: date.year() function
description: >
The `date.year()` function returns the year of a specified time.
menu:
v2_0_ref:
name: date.year
parent: Date
weight: 301
draft: true
---
The `date.year()` function returns the year of a specified time.
_**Function type:** Transformation_
```js
import "date"
date.year(t: 2019-07-17T12:05:21.012Z)
// Returns 2019
```
## Parameters
### t
The time to operate on.
_**Data type:** Time_

View File

@ -0,0 +1,22 @@
---
title: Flux runtime package
list_title: Runtime package
description: >
The Flux runtime package includes functions that provide information about the
current Flux runtime. Import the `runtime` package.
menu:
v2_0_ref:
name: Runtime
parent: Flux packages and functions
weight: 202
v2.0/tags: [runtime, functions, package]
---
The Flux runtime package includes functions that provide information about the
current Flux runtime. Import the `runtime` package:
```js
import "runtime"
```
{{< children type="functions" show="pages" >}}

View File

@ -0,0 +1,20 @@
---
title: runtime.version() function
description: The `runtime.version()` function returns the current Flux version.
menu:
v2_0_ref:
name: runtime.version
parent: Runtime
weight: 401
---
The `runtime.version()` function returns the current Flux version.
_**Function type:** Miscellaneous_
_**Output data type:** String_
```js
import "runtime"
runtime.version()
```

View File

@ -11,13 +11,37 @@ aliases:
--- ---
{{% note %}} {{% note %}}
_The latest release of InfluxDB v2.0 alpha includes **Flux v0.37.2**. _The latest release of InfluxDB v2.0 alpha includes **Flux v0.38.0**.
Though newer versions of Flux may be available, they will not be included with Though newer versions of Flux may be available, they will not be included with
InfluxDB until the next InfluxDB v2.0 release._ InfluxDB until the next InfluxDB v2.0 release._
{{% /note %}} {{% /note %}}
--- ---
## v0.38.0 [2019-08-06]
### Features
- Update selectors to operate on time columns.
- Add `relativeStrengthIndex()` transformation.
- Add double and triple exponential average transformations (`doubleEMA()` and `tripleEMA()`).
- Add `holtWinters()` transformation.
- Add `keepFirst` parameter to `difference()`.
- DatePart equivalent functions.
- Add runtime package.
- Add and subtract duration literal arithmetic.
- Allow `keep()` to run regardless of nonexistent columns.
If all columns given are nonexistent, `keep()` returns an empty table.
- Scanner returns positioning.
### Bug fixes
- Function resolver now keeps track of local assignments that may be evaluated at runtime.
- Fixed InfluxDB test errors.
- Add range to tests to pass in InfluxDB.
- Allow converting a duration to a duration.
- Catch integer overflow and underflow for literals.
---
## v0.37.2 [2019-07-24] ## v0.37.2 [2019-07-24]
- _General cleanup of internal code._ - _General cleanup of internal code._