Merge pull request #50 from influxdata/strings-influxdbv1-functions
Strings and InfluxDB v1 functionspull/52/head
commit
f863def607
|
@ -9,8 +9,6 @@ weight: 101
|
|||
---
|
||||
|
||||
Flux's functional syntax allows you to retrieve, transform, process, and output data easily.
|
||||
There is a large library of built-in and importable functions.
|
||||
You can also [create your own custom functions](/v2.0/query-data/guides/custom-functions)
|
||||
to perform operations that suit your needs.
|
||||
There is a large library of built-in and importable functions:
|
||||
|
||||
{{< children >}}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
---
|
||||
title: Flux built-in functions
|
||||
description: placeholder
|
||||
description: >
|
||||
Built-in functions provide a necessary foundation for working with data using Flux.
|
||||
They do not require an import statement and are usable without any extra setup.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: Built-in
|
||||
|
@ -8,4 +10,9 @@ menu:
|
|||
weight: 201
|
||||
---
|
||||
|
||||
Placeholder
|
||||
Built-in functions provide a necessary foundation for working with data using Flux.
|
||||
Because these functions are "built-in," they do not require an `import` statement and are usable without any extra setup.
|
||||
|
||||
Built-in functions are grouped into the following categories:
|
||||
|
||||
{{< children >}}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
---
|
||||
title: Flux InfluxDB v1 functions
|
||||
description: placeholder
|
||||
description: >
|
||||
InfluxDB v1 Flux functions provide tools for managing data from an InfluxDB v1.x
|
||||
database or structured using the InfluxDB v1 data structure.
|
||||
To use them, import the "influxdata/influxdb/v1" package.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: InfluxDB v1
|
||||
|
@ -8,4 +11,12 @@ menu:
|
|||
weight: 202
|
||||
---
|
||||
|
||||
Placeholder
|
||||
InfluxDB v1 Flux functions provide tools for managing data from an InfluxDB v1.x
|
||||
database or structured using the InfluxDB v1 data structure.
|
||||
To use them, import the `influxdata/influxdb/v1` package:
|
||||
|
||||
```js
|
||||
import "influxdata/influxdb/v1"
|
||||
```
|
||||
|
||||
{{< children type="functions" show="pages" >}}
|
||||
|
|
|
@ -1,37 +1,41 @@
|
|||
---
|
||||
title: influxFieldsAsCols() function
|
||||
description: The influxFieldsAsCols() function is pivots a table and automatically aligns fields within each input table that have the same timestamp.
|
||||
title: v1.fieldsAsCols() function
|
||||
description: The v1.fieldsAsCols() 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
|
||||
- /v2.0/reference/flux/functions/transformations/influxfieldsascols
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: influxFieldsAsCols
|
||||
parent: built-in-transformations
|
||||
weight: 401
|
||||
name: v1.fieldsAsCols
|
||||
parent: InfluxDB v1
|
||||
weight: 301
|
||||
---
|
||||
|
||||
The `influxFieldsAsCols()` function is a special application of the `pivot()` function that
|
||||
The `v1.fieldsAsCols()` 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()
|
||||
import "influxdata/influxdb/v1"
|
||||
|
||||
v1.fieldsAsCols()
|
||||
```
|
||||
|
||||
## Examples
|
||||
```js
|
||||
import "influxdata/influxdb/v1"
|
||||
|
||||
from(bucket:"telegraf/autogen")
|
||||
|> range(start: -1h)
|
||||
|> filter(fn: (r) => r._measurement == "cpu")
|
||||
|> influxFieldsAsCols()
|
||||
|> v1.fieldsAsCols()
|
||||
|> keep(columns: ["_time", "cpu", "usage_idle", "usage_user"])
|
||||
```
|
||||
|
||||
## Function definition
|
||||
```js
|
||||
influxFieldsAsCols = (tables=<-) =>
|
||||
fieldsAsCols = (tables=<-) =>
|
||||
tables
|
||||
|> pivot(
|
||||
rowKey:["_time"],
|
||||
|
@ -39,3 +43,6 @@ influxFieldsAsCols = (tables=<-) =>
|
|||
valueColumn: "_value"
|
||||
)
|
||||
```
|
||||
|
||||
_**Used functions:**
|
||||
[pivot()](/v2.0/reference/flux/functions/built-in/transformations/pivot)_
|
|
@ -0,0 +1,34 @@
|
|||
---
|
||||
title: v1.measurements() function
|
||||
description: The v1.measurements() function returns a list of measurements in a specific bucket.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: v1.measurements
|
||||
parent: InfluxDB v1
|
||||
weight: 301
|
||||
---
|
||||
|
||||
The `v1.measurements()` function returns a list of measurements in a specific bucket.
|
||||
The return value is always a single table with a single column, `_value`.
|
||||
|
||||
```js
|
||||
import "influxdata/influxdb/v1"
|
||||
|
||||
v1.measurements(bucket: "example-bucket")
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### bucket
|
||||
The bucket from which to list measurements.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
## Function definition
|
||||
```js
|
||||
measurements = (bucket) =>
|
||||
tagValues(bucket: bucket, tag: "_measurement")
|
||||
```
|
||||
|
||||
_**Used functions:**
|
||||
[tagValues()](/v2.0/reference/flux/functions/influxdb-v1/tagvalues)_
|
|
@ -0,0 +1,44 @@
|
|||
---
|
||||
title: v1.measurementTagKeys() function
|
||||
description: The v1.measurementTagKeys() function returns a list of tag keys for a specific measurement.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: v1.measurementTagKeys
|
||||
parent: InfluxDB v1
|
||||
weight: 301
|
||||
---
|
||||
|
||||
The `v1.measurementTagKeys()` function returns a list of tag keys for a specific measurement.
|
||||
The return value is always a single table with a single column, `_value`.
|
||||
|
||||
```js
|
||||
import "influxdata/influxdb/v1"
|
||||
|
||||
v1.measurementTagKeys(
|
||||
bucket: "example-bucket",
|
||||
measurement: "cpu"
|
||||
)
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### bucket
|
||||
The bucket from which to return tag keys for a specific measurement.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
### measurement
|
||||
The measurement from which to return tag keys.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
## Function definition
|
||||
```js
|
||||
measurementTagKeys = (bucket, measurement) =>
|
||||
tagKeys(
|
||||
bucket: bucket,
|
||||
predicate: (r) => r._measurement == measurement)
|
||||
```
|
||||
|
||||
_**Used functions:**
|
||||
[tagKeys()](/v2.0/reference/flux/functions/influxdb-v1/tagkeys)_
|
|
@ -0,0 +1,55 @@
|
|||
---
|
||||
title: v1.measurementTagValues() function
|
||||
description: The v1.measurementTagValues() function returns a list of tag values for a specific measurement.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: v1.measurementTagValues
|
||||
parent: InfluxDB v1
|
||||
weight: 301
|
||||
---
|
||||
|
||||
The `v1.measurementTagValues()` function returns a list of tag values for a specific measurement.
|
||||
The return value is always a single table with a single column, `_value`.
|
||||
|
||||
|
||||
|
||||
```js
|
||||
import "influxdata/influxdb/v1"
|
||||
|
||||
v1.measurementTagValues(
|
||||
bucket: "example-bucket",
|
||||
measurement: "cpu",
|
||||
tag: "host"
|
||||
)
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### bucket
|
||||
The bucket from which to return tag values for a specific measurement.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
### measurement
|
||||
The measurement from which to return tag values.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
### tag
|
||||
The tag from which to return all unique values.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
|
||||
## Function definition
|
||||
```js
|
||||
measurementTagValues = (bucket, measurement, tag) =>
|
||||
tagValues(
|
||||
bucket: bucket,
|
||||
tag: tag,
|
||||
predicate: (r) => r._measurement == measurement
|
||||
)
|
||||
```
|
||||
|
||||
_**Used functions:**
|
||||
[tagValues()](/v2.0/reference/flux/functions/influxdb-v1/tagvalues)_
|
|
@ -0,0 +1,70 @@
|
|||
---
|
||||
title: v1.tagKeys() function
|
||||
description: The v1.tagKeys() function returns a list of tag keys for all series that match the predicate.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: v1.tagKeys
|
||||
parent: InfluxDB v1
|
||||
weight: 301
|
||||
---
|
||||
|
||||
The `v1.tagKeys()` function returns a list of tag keys for all series that match the [`predicate`](#predicate).
|
||||
The return value is always a single table with a single column, `_value`.
|
||||
|
||||
```js
|
||||
import "influxdata/influxdb/v1"
|
||||
|
||||
v1.tagKeys(
|
||||
bucket: "example-bucket",
|
||||
predicate: (r) => true,
|
||||
start: -30d
|
||||
)
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### bucket
|
||||
The bucket from which to list tag keys.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
### predicate
|
||||
The predicate function that filters tag keys.
|
||||
_Defaults to `(r) => true`._
|
||||
|
||||
_**Data type:** Function_
|
||||
|
||||
### start
|
||||
Specifies the oldest time to be included in the results.
|
||||
_Defaults to `-30d`._
|
||||
|
||||
Relative start times are defined using negative durations.
|
||||
Negative durations are relative to now.
|
||||
Absolute start times are defined using timestamps.
|
||||
|
||||
_**Data type:** Duration_
|
||||
|
||||
## Examples
|
||||
```js
|
||||
import "influxdata/influxdb/v1"
|
||||
|
||||
v1.tagKeys(bucket: "my-bucket")
|
||||
```
|
||||
|
||||
|
||||
## Function definition
|
||||
```js
|
||||
tagKeys = (bucket, predicate=(r) => true, start=-30d) =>
|
||||
from(bucket: bucket)
|
||||
|> range(start: start)
|
||||
|> filter(fn: predicate)
|
||||
|> keys()
|
||||
|> keep(columns: ["_value"])
|
||||
```
|
||||
|
||||
_**Used functions:**
|
||||
[from](/v2.0/reference/flux/functions/built-in/inputs/from/),
|
||||
[range](/v2.0/reference/flux/functions/built-in/transformations/range/),
|
||||
[filter](/v2.0/reference/flux/functions/built-in/transformations/filter/),
|
||||
[keys](/v2.0/reference/flux/functions/built-in/transformations/keys/),
|
||||
[keep](/v2.0/reference/flux/functions/built-in/transformations/keep/)_
|
|
@ -0,0 +1,81 @@
|
|||
---
|
||||
title: v1.tagValues() function
|
||||
description: placeholder
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: v1.tagValues
|
||||
parent: InfluxDB v1
|
||||
weight: 301
|
||||
---
|
||||
|
||||
The `v1.tagValues()` function returns a list unique values for a given tag.
|
||||
The return value is always a single table with a single column, `_value`.
|
||||
|
||||
|
||||
```js
|
||||
import "influxdata/influxdb/v1"
|
||||
|
||||
v1.tagValues(
|
||||
bucket: "example-bucket",
|
||||
tag: "host",
|
||||
predicate: (r) => true,
|
||||
start: -30d
|
||||
)
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### bucket
|
||||
The bucket from which to list tag values.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
### tag
|
||||
The tag for which to return unique values.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
### predicate
|
||||
The predicate function that filters tag values.
|
||||
_Defaults to `(r) => true`._
|
||||
|
||||
_**Data type:** Function_
|
||||
|
||||
### start
|
||||
Specifies the oldest time to be included in the results.
|
||||
_Defaults to `-30d`._
|
||||
|
||||
Relative start times are defined using negative durations.
|
||||
Negative durations are relative to now.
|
||||
Absolute start times are defined using timestamps.
|
||||
|
||||
_**Data type:** Duration_
|
||||
|
||||
## Examples
|
||||
```js
|
||||
import "influxdata/influxdb/v1"
|
||||
|
||||
v1.tagKeys(
|
||||
bucket: "my-bucket",
|
||||
tag: "host",
|
||||
)
|
||||
```
|
||||
|
||||
## Function definition
|
||||
```js
|
||||
tagValues = (bucket, tag, predicate=(r) => true, start=-30d) =>
|
||||
from(bucket: bucket)
|
||||
|> range(start: start)
|
||||
|> filter(fn: predicate)
|
||||
|> group(columns: [tag])
|
||||
|> distinct(column: tag)
|
||||
|> keep(columns: ["_value"])
|
||||
```
|
||||
|
||||
_**Used functions:**
|
||||
[from](/v2.0/reference/flux/functions/built-in/inputs/from/),
|
||||
[range](/v2.0/reference/flux/functions/built-in/transformations/range/),
|
||||
[filter](/v2.0/reference/flux/functions/built-in/transformations/filter/),
|
||||
[group](/v2.0/reference/flux/functions/built-in/transformations/group/),
|
||||
[distinct](/v2.0/reference/flux/functions/built-in/transformations/selectors/distinct/),
|
||||
[keep](/v2.0/reference/flux/functions/built-in/transformations/keep/)_
|
|
@ -1,6 +1,8 @@
|
|||
---
|
||||
title: Flux string functions
|
||||
description: placeholder
|
||||
description: >
|
||||
String functions provide tools for manipulating strings in Flux.
|
||||
To use them, import the "strings" package:
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: Strings
|
||||
|
@ -8,4 +10,11 @@ menu:
|
|||
weight: 203
|
||||
---
|
||||
|
||||
Placeholder
|
||||
String functions provide tools for manipulating strings in Flux.
|
||||
To use them, import the `strings` package:
|
||||
|
||||
```js
|
||||
import "strings"
|
||||
```
|
||||
|
||||
{{< children type="functions" show="pages" >}}
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
---
|
||||
title: strings.title() function
|
||||
description: The strings.title() function converts a string to title case.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: strings.title
|
||||
parent: Strings
|
||||
weight: 301
|
||||
---
|
||||
|
||||
The `strings.title()` function converts a string to title case.
|
||||
|
||||
_**Output data type:** String_
|
||||
|
||||
```js
|
||||
import "strings"
|
||||
|
||||
strings.title(v: "a flux of foxes")
|
||||
|
||||
// returns "A Flux Of Foxes"
|
||||
```
|
||||
|
||||
## Paramters
|
||||
|
||||
### v
|
||||
The string value to convert.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
## Examples
|
||||
|
||||
###### Convert all values of a column to title case
|
||||
```js
|
||||
import "strings"
|
||||
|
||||
data
|
||||
|> map(fn:(r) => strings.title(v: r.pageTitle))
|
||||
```
|
|
@ -0,0 +1,38 @@
|
|||
---
|
||||
title: strings.toLower() function
|
||||
description: The strings.toLower() function converts a string to lower case.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: strings.toLower
|
||||
parent: Strings
|
||||
weight: 301
|
||||
---
|
||||
|
||||
The `strings.toLower()` function converts a string to lower case.
|
||||
|
||||
_**Output data type:** String_
|
||||
|
||||
```js
|
||||
import "strings"
|
||||
|
||||
strings.toLower(v: "KOALA")
|
||||
|
||||
// returns "koala"
|
||||
```
|
||||
|
||||
## Paramters
|
||||
|
||||
### v
|
||||
The string value to convert.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
## Examples
|
||||
|
||||
###### Convert all values of a column to lower case
|
||||
```js
|
||||
import "strings"
|
||||
|
||||
data
|
||||
|> map(fn:(r) => strings.toLower(v: r.exclamation))
|
||||
```
|
|
@ -0,0 +1,38 @@
|
|||
---
|
||||
title: strings.toUpper() function
|
||||
description: The strings.toUpper() function converts a string to upper case.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: strings.toUpper
|
||||
parent: Strings
|
||||
weight: 301
|
||||
---
|
||||
|
||||
The `strings.toUpper()` function converts a string to upper case.
|
||||
|
||||
_**Output data type:** String_
|
||||
|
||||
```js
|
||||
import "strings"
|
||||
|
||||
strings.toUpper(v: "koala")
|
||||
|
||||
// returns "KOALA"
|
||||
```
|
||||
|
||||
## Paramters
|
||||
|
||||
### v
|
||||
The string value to convert.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
## Examples
|
||||
|
||||
###### Convert all values of a column to upper case
|
||||
```js
|
||||
import "strings"
|
||||
|
||||
data
|
||||
|> map(fn:(r) => strings.toUpper(v: r.envVars))
|
||||
```
|
|
@ -0,0 +1,47 @@
|
|||
---
|
||||
title: strings.trim() function
|
||||
description: >
|
||||
The strings.trim() function removes leading and trailing characters specified
|
||||
in the cutset from a string.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: strings.trim
|
||||
parent: Strings
|
||||
weight: 301
|
||||
---
|
||||
|
||||
The `strings.trim()` function removes leading and trailing characters specified
|
||||
in the [`cutset`](#cutset) from a string.
|
||||
|
||||
_**Output data type:** String_
|
||||
|
||||
```js
|
||||
import "strings"
|
||||
|
||||
strings.trim(v: ".abc.", cutset: ".")
|
||||
|
||||
// returns "abc"
|
||||
```
|
||||
|
||||
## Paramters
|
||||
|
||||
### v
|
||||
The string value from which to trim characters.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
### cutset
|
||||
The leading and trailing characters to trim from the string value.
|
||||
Only characters that match the `cutset` string exactly are trimmed.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
## Examples
|
||||
|
||||
###### Trim leading and trailing periods from all values in a column
|
||||
```js
|
||||
import "strings"
|
||||
|
||||
data
|
||||
|> map(fn:(r) => strings.trim(v: r.variables, cutset: "."))
|
||||
```
|
|
@ -0,0 +1,38 @@
|
|||
---
|
||||
title: strings.trimSpace() function
|
||||
description: The strings.trimSpace() function removes leading and trailing spaces from a string.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: strings.trimSpace
|
||||
parent: Strings
|
||||
weight: 301
|
||||
---
|
||||
|
||||
The `strings.trimSpace()` function removes leading and trailing spaces from a string.
|
||||
|
||||
_**Output data type:** String_
|
||||
|
||||
```js
|
||||
import "strings"
|
||||
|
||||
strings.trimSpace(v: " abc ")
|
||||
|
||||
// returns "abc"
|
||||
```
|
||||
|
||||
## Paramters
|
||||
|
||||
### v
|
||||
The string value from which to trim spaces.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
## Examples
|
||||
|
||||
###### Trim leading and trailing spaces from all values in a column
|
||||
```js
|
||||
import "strings"
|
||||
|
||||
data
|
||||
|> map(fn:(r) => strings.trimSpace(v: r.userInput))
|
||||
```
|
Loading…
Reference in New Issue