add stream and table functions
parent
fb272bce5e
commit
166c99ac75
|
@ -0,0 +1,34 @@
|
||||||
|
---
|
||||||
|
title: Flux stream and table functions
|
||||||
|
listtitle: Stream and table functions
|
||||||
|
seotitle: Flux built-in stream and table functions
|
||||||
|
description: >
|
||||||
|
placeholder
|
||||||
|
weight: 401
|
||||||
|
menu:
|
||||||
|
v2_0_ref:
|
||||||
|
name: Stream & table
|
||||||
|
parent: built-in-transformations
|
||||||
|
v2.0/tags: [transformations, built-in, functions, stream, table]
|
||||||
|
---
|
||||||
|
|
||||||
|
Use stream and table functions to extract a table from a stream of tables and access its
|
||||||
|
columns and records.
|
||||||
|
|
||||||
|
##### Example stream and table functions
|
||||||
|
```js
|
||||||
|
data = from(bucket:"example-bucket")
|
||||||
|
|> range(start: -5m)
|
||||||
|
|> filter(fn:(r) => r._measurement == "cpu")
|
||||||
|
|
||||||
|
// Extract the first available table for which "_field" is equal to "usage_idle"
|
||||||
|
t = data |> tableFind(fn: (key) => key._field == "usage_idle")
|
||||||
|
|
||||||
|
// Extract the "_value" column from the table
|
||||||
|
values = t |> getColumn(column: "_value")
|
||||||
|
|
||||||
|
// Extract the first record from the table
|
||||||
|
r0 = t |> getRecord(idx: 0)
|
||||||
|
```
|
||||||
|
|
||||||
|
{{< children type="functions" >}}
|
|
@ -0,0 +1,39 @@
|
||||||
|
---
|
||||||
|
title: getColumn() function
|
||||||
|
description: >
|
||||||
|
The `getColumn()` function extracts a column from a table given its label.
|
||||||
|
If the label is not present in the set of columns, the function errors.
|
||||||
|
menu:
|
||||||
|
v2_0_ref:
|
||||||
|
name: getColumn
|
||||||
|
parent: Stream & table
|
||||||
|
weight: 501
|
||||||
|
---
|
||||||
|
|
||||||
|
The `getColumn()` function extracts a column from a table given its label.
|
||||||
|
If the label is not present in the set of columns, the function errors.
|
||||||
|
|
||||||
|
_**Function type:** Stream and table_
|
||||||
|
|
||||||
|
```js
|
||||||
|
getColumn(column: "_value")
|
||||||
|
```
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
### column
|
||||||
|
The name of the column to extract.
|
||||||
|
|
||||||
|
_**Data type:** String_
|
||||||
|
|
||||||
|
## Example
|
||||||
|
```js
|
||||||
|
vs = from(bucket:"example-bucket")
|
||||||
|
|> range(start: -5m)
|
||||||
|
|> filter(fn:(r) => r._measurement == "cpu")
|
||||||
|
|> tableFind(fn: (key) => key._field == "usage_idle")
|
||||||
|
|> getColumn(column: "_value")
|
||||||
|
|
||||||
|
// Use column values
|
||||||
|
x = vs[0] + vs[1]
|
||||||
|
```
|
|
@ -0,0 +1,39 @@
|
||||||
|
---
|
||||||
|
title: getRecord() function
|
||||||
|
description: >
|
||||||
|
The `getRecord()` function extracts a record from a table given its index.
|
||||||
|
If the index is out of bounds, the function errors.
|
||||||
|
menu:
|
||||||
|
v2_0_ref:
|
||||||
|
name: getRecord
|
||||||
|
parent: Stream & table
|
||||||
|
weight: 501
|
||||||
|
---
|
||||||
|
|
||||||
|
The `getRecord()` function extracts a record from a table given the record's index.
|
||||||
|
If the index is out of bounds, the function errors.
|
||||||
|
|
||||||
|
_**Function type:** Stream and table_
|
||||||
|
|
||||||
|
```js
|
||||||
|
getRecord(idx: 0)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
### idx
|
||||||
|
The index of the record to extract.
|
||||||
|
|
||||||
|
_**Data type:** Integer_
|
||||||
|
|
||||||
|
## Example
|
||||||
|
```js
|
||||||
|
r0 = from(bucket:"example-bucket")
|
||||||
|
|> range(start: -5m)
|
||||||
|
|> filter(fn:(r) => r._measurement == "cpu")
|
||||||
|
|> tableFind(fn: (key) => key._field == "usage_idle")
|
||||||
|
|> getRecord(idx: 0)
|
||||||
|
|
||||||
|
// Use record values
|
||||||
|
x = r0._field + "--" + r0._measurement
|
||||||
|
```
|
|
@ -0,0 +1,50 @@
|
||||||
|
---
|
||||||
|
title: tableFind() function
|
||||||
|
description: >
|
||||||
|
The `tableFind()` function extracts the first table in a stream of tables whose
|
||||||
|
group key values match a predicate. If no table is found, the function errors.
|
||||||
|
menu:
|
||||||
|
v2_0_ref:
|
||||||
|
name: tableFind
|
||||||
|
parent: Stream & table
|
||||||
|
weight: 501
|
||||||
|
---
|
||||||
|
|
||||||
|
The `tableFind()` function extracts the first table in a stream of tables whose
|
||||||
|
group key values match a predicate. If no table is found, the function errors.
|
||||||
|
|
||||||
|
_**Function type:** Stream and table_
|
||||||
|
|
||||||
|
```js
|
||||||
|
tableFind(column: "_value")
|
||||||
|
```
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
### fn
|
||||||
|
A predicate function for matching keys in a table's group key.
|
||||||
|
`tableFind` returns the first table that resolves as `true`.
|
||||||
|
It expects a `key` argument which represents a group key in the input stream.
|
||||||
|
|
||||||
|
_**Data type:** Function_
|
||||||
|
|
||||||
|
##### Example fn function
|
||||||
|
```js
|
||||||
|
(key) => key._field == "fieldName"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Example
|
||||||
|
```js
|
||||||
|
t = from(bucket:"example-bucket")
|
||||||
|
|> range(start: -5m)
|
||||||
|
|> filter(fn:(r) => r._measurement == "cpu")
|
||||||
|
|> tableFind(fn: (key) => key._field == "usage_idle")
|
||||||
|
|
||||||
|
// t represents the first table in a stream whose group key
|
||||||
|
// contains "_field" with a value of "usage_idle".
|
||||||
|
```
|
||||||
|
|
||||||
|
{{% note %}}
|
||||||
|
You can use `t` from the example above as input for [`getColumn()`](/v2.0/reference/flux/functions/built-in/transformations/stream-table/getcolumn/)
|
||||||
|
and [`getRecord()`](/v2.0/reference/flux/functions/built-in/transformations/stream-table/getrecord/).
|
||||||
|
{{% /note %}}
|
Loading…
Reference in New Issue