From 166c99ac75b49a7328a243560752de6f24e120e9 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Mon, 13 May 2019 16:16:08 -0600 Subject: [PATCH 1/2] add stream and table functions --- .../transformations/stream-table/_index.md | 34 +++++++++++++ .../transformations/stream-table/getcolumn.md | 39 +++++++++++++++ .../transformations/stream-table/getrecord.md | 39 +++++++++++++++ .../transformations/stream-table/tablefind.md | 50 +++++++++++++++++++ 4 files changed, 162 insertions(+) create mode 100644 content/v2.0/reference/flux/functions/built-in/transformations/stream-table/_index.md create mode 100644 content/v2.0/reference/flux/functions/built-in/transformations/stream-table/getcolumn.md create mode 100644 content/v2.0/reference/flux/functions/built-in/transformations/stream-table/getrecord.md create mode 100644 content/v2.0/reference/flux/functions/built-in/transformations/stream-table/tablefind.md diff --git a/content/v2.0/reference/flux/functions/built-in/transformations/stream-table/_index.md b/content/v2.0/reference/flux/functions/built-in/transformations/stream-table/_index.md new file mode 100644 index 000000000..514f0d730 --- /dev/null +++ b/content/v2.0/reference/flux/functions/built-in/transformations/stream-table/_index.md @@ -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" >}} diff --git a/content/v2.0/reference/flux/functions/built-in/transformations/stream-table/getcolumn.md b/content/v2.0/reference/flux/functions/built-in/transformations/stream-table/getcolumn.md new file mode 100644 index 000000000..2bc462efb --- /dev/null +++ b/content/v2.0/reference/flux/functions/built-in/transformations/stream-table/getcolumn.md @@ -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] +``` diff --git a/content/v2.0/reference/flux/functions/built-in/transformations/stream-table/getrecord.md b/content/v2.0/reference/flux/functions/built-in/transformations/stream-table/getrecord.md new file mode 100644 index 000000000..9e1f35826 --- /dev/null +++ b/content/v2.0/reference/flux/functions/built-in/transformations/stream-table/getrecord.md @@ -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 +``` diff --git a/content/v2.0/reference/flux/functions/built-in/transformations/stream-table/tablefind.md b/content/v2.0/reference/flux/functions/built-in/transformations/stream-table/tablefind.md new file mode 100644 index 000000000..dc4de72cd --- /dev/null +++ b/content/v2.0/reference/flux/functions/built-in/transformations/stream-table/tablefind.md @@ -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 %}} From c0e06afbf6b17ef3eb99b0138276cfbca5b26e7e Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Mon, 13 May 2019 16:20:55 -0600 Subject: [PATCH 2/2] updated frontmatter for stream and table functions index page --- .../built-in/transformations/stream-table/_index.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/content/v2.0/reference/flux/functions/built-in/transformations/stream-table/_index.md b/content/v2.0/reference/flux/functions/built-in/transformations/stream-table/_index.md index 514f0d730..9206961fd 100644 --- a/content/v2.0/reference/flux/functions/built-in/transformations/stream-table/_index.md +++ b/content/v2.0/reference/flux/functions/built-in/transformations/stream-table/_index.md @@ -1,9 +1,10 @@ --- title: Flux stream and table functions -listtitle: Stream and table functions +list_title: Stream and table functions seotitle: Flux built-in stream and table functions description: > - placeholder + Use stream and table functions to extract a table from a stream of tables and access its + columns and records. weight: 401 menu: v2_0_ref: @@ -13,7 +14,7 @@ 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. +columns and records. ##### Example stream and table functions ```js