Merge pull request #1094 from influxdata/flux/update-reduce

Remove 'with' operator support from 'reduce()' doc
pull/1092/head
Scott Anderson 2020-06-09 16:24:09 -06:00 committed by GitHub
commit 0a96708f87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 16 deletions

View File

@ -86,24 +86,12 @@ identity: {sum: 0.0, count: 0.0}
## Important notes
#### Preserve columns
#### Dropped columns
By default, `reduce()` drops any columns that:
1. Are not part of the input table's group key.
1. Are not part of the input table's [group key](/v2.0/reference/glossary/#group-key).
2. Are not explicitly mapped in the `reduce()` function.
This often results in the `_time` column being dropped.
To preserve the `_time` column and other columns that do not meet the criteria above,
use the `with` operator to map values in the `r` object.
The `with` operator updates a column if it already exists,
creates a new column if it doesn't exist, and includes all existing columns in
the output table.
```js
reduce(fn: (r) => ({ r with newColumn: r._value * 2 }))
```
## Examples
##### Compute the sum of the value column
@ -157,14 +145,13 @@ from(bucket:"example-bucket")
)
```
##### Calculate the average and preserve existing columns
##### Calculate the average
```js
from(bucket: "example-bucket")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r._measurement == "mem" and r._field == "used_percent")
|> window(every: 5m)
|> reduce(fn: (r, accumulator) => ({
r with
count: accumulator.count + 1,
total: accumulator.total + r._value,
avg: (accumulator.total + r._value) / float(v: accumulator.count)