diff --git a/content/v2.0/query-data/flux/scalar-values.md b/content/v2.0/query-data/flux/scalar-values.md index 4eca5112d..3bb7a8542 100644 --- a/content/v2.0/query-data/flux/scalar-values.md +++ b/content/v2.0/query-data/flux/scalar-values.md @@ -32,9 +32,9 @@ This lets you, for example, dynamically set variables using query results. **To extract scalar values from output:** -1. [Extract a table](#extract-a-table). -2. [Extract a column from the table](#extract-a-column-from-the-table) - _**or**_ [extract a row from the table](#extract-a-row-from-the-table). +1. [Extract a column from the input stream](#extract-a-column) + _**or**_ [extract a row from the input stream](#extract-a-row). +2. Use the returned array or object to reference scalar values. _The samples on this page use the [sample data provided below](#sample-data)._ @@ -48,61 +48,33 @@ _The samples on this page use the [sample data provided below](#sample-data)._ See [#15321](https://github.com/influxdata/influxdb/issues/15231). {{% /warn %}} -## Extract a table +## Table extraction Flux formats query results as a stream of tables. -To extract a scalar value from a stream of tables, you must first extract a single table. - -to extract a single table from the stream of tables. - -{{% note %}} -If query results include only one table, it is still formatted as a stream of tables. -You still must extract that table from the stream. -{{% /note %}} - -Use [`tableFind()`](/v2.0/reference/flux/stdlib/built-in/transformations/stream-table/tablefind/) -to extract the **first** table whose [group key](/v2.0/reference/glossary/#group-key) -values match the `fn` [predicate function](/v2.0/reference/glossary/#predicate-expression). -The predicate function requires a `key` object, which represents the group key of -each table. - -```js -sampleData - |> tableFind(fn: (key) => - key._field == "temp" and - key.location == "sfo" - ) -``` - -The example above returns a single table: - -| _time | location | _field | _value | -|:----- |:--------:|:------:| ------:| -| 2019-11-01T12:00:00Z | sfo | temp | 65.1 | -| 2019-11-01T13:00:00Z | sfo | temp | 66.2 | -| 2019-11-01T14:00:00Z | sfo | temp | 66.3 | -| 2019-11-01T15:00:00Z | sfo | temp | 66.8 | +Both [`findColumn()`](/v2.0/reference/flux/stdlib/built-in/transformations/stream-table/findcolumn/) +and [`findRecord()`](/v2.0/reference/flux/stdlib/built-in/transformations/stream-table/findrecord/) +extract the first table in a stream of tables whose [group key](/v2.0/reference/glossary/#group-key) +values match the `fn` [predicate function](/v2.0/reference/glossary/#predicate-function). {{% note %}} #### Extract the correct table -Flux functions do not guarantee table order and `tableFind()` returns only the -**first** table that matches the `fn` predicate. -To extract the table that includes the data you actually want, be very specific in -your predicate function or filter and transform your data to minimize the number -of tables piped-forward into `tableFind()`. +Flux functions do not guarantee table order. +`findColumn()` and `findRecord` extract only the **first** table that matches the `fn` predicate. +To extract the correct table, be very specific in your predicate function or +filter and transform your data to minimize the number of tables piped-forward into the functions. {{% /note %}} -## Extract a column from the table -Use the [`getColumn()` function](/v2.0/reference/flux/stdlib/built-in/transformations/stream-table/getcolumn/) +## Extract a column +Use the [`findColumn()` function](/v2.0/reference/flux/stdlib/built-in/transformations/stream-table/findcolumn/) to output an array of values from a specific column in the extracted table. +_See [Sample data](#sample-data) below._ ```js sampleData - |> tableFind(fn: (key) => - key._field == "temp" and - key.location == "sfo" + |> findColumn( + fn: (key) => key._field == "temp" and key.location == "sfo", + column: "_value" ) - |> getColumn(column: "_value") // Returns [65.1, 66.2, 66.3, 66.8] ``` @@ -113,13 +85,14 @@ In the example below, `SFOTemps` represents the array of values. Reference a specific index (integer starting from `0`) in the array to return the value at that index. +_See [Sample data](#sample-data) below._ + ```js SFOTemps = sampleData - |> tableFind(fn: (key) => - key._field == "temp" and - key.location == "sfo" + |> findColumn( + fn: (key) => key._field == "temp" and key.location == "sfo", + column: "_value" ) - |> getColumn(column: "_value") SFOTemps // Returns [65.1, 66.2, 66.3, 66.8] @@ -131,19 +104,18 @@ SFOTemps[2] // Returns 66.3 ``` -## Extract a row from the table -Use the [`getRecord()` function](/v2.0/reference/flux/stdlib/built-in/transformations/stream-table/getrecord/) +## Extract a row +Use the [`findRecord()` function](/v2.0/reference/flux/stdlib/built-in/transformations/stream-table/findrecord/) to output data from a single row in the extracted table. Specify the index of the row to output using the `idx` parameter. The function outputs an object with key-value pairs for each column. ```js sampleData - |> tableFind(fn: (key) => - key._field == "temp" and - key.location == "sfo" + |> findRecord( + fn: (key) => key._field == "temp" and key.location == "sfo", + idx: 0 ) - |> getRecord(idx: 0) // Returns { // _time:2019-11-11T12:00:00Z, @@ -161,11 +133,10 @@ keys in the object. ```js tempInfo = sampleData - |> tableFind(fn: (key) => - key._field == "temp" and - key.location == "sfo" + |> findRecord( + fn: (key) => key._field == "temp" and key.location == "sfo", + idx: 0 ) - |> getRecord(idx: 0) tempInfo // Returns { @@ -190,8 +161,10 @@ Create custom helper functions to extract scalar values from query output. // Define a helper function to extract field values getFieldValue = (tables=<-, field) => { extract = tables - |> tableFind(fn: (key) => key._field == field) - |> getColumn(column: "_value") + |> findColumn( + fn: (key) => key._field == field, + column: "_value" + ) return extract[0] } @@ -210,8 +183,10 @@ lastJFKTemp // Define a helper function to extract a row as an object getRow = (tables=<-, field, idx=0) => { extract = tables - |> tableFind(fn: (key) => true) - |> getRecord(idx: idx) + |> findRecord( + fn: (key) => true, + idx: idx + ) return extract } diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/columns.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/columns.md index 9bd20c876..9c09ff63c 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/columns.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/columns.md @@ -11,7 +11,7 @@ menu: v2_0_ref: name: columns parent: built-in-transformations -weight: 401 +weight: 402 related: - https://docs.influxdata.com/influxdb/latest/query_language/schema_exploration/#show-measurements, InfluxQL – SHOW MEASUREMENTS - https://docs.influxdata.com/influxdb/latest/query_language/schema_exploration/#show-field-keys, InfluxQL – SHOW FIELD KEYS diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/cumulativesum.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/cumulativesum.md index 1def460fe..29bf1635a 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/cumulativesum.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/cumulativesum.md @@ -8,7 +8,7 @@ menu: v2_0_ref: name: cumulativeSum parent: built-in-transformations -weight: 401 +weight: 402 related: - /v2.0/query-data/flux/cumulativesum/ - https://docs.influxdata.com/influxdb/latest/query_language/functions/#cumulative-sum, InfluxQL – CUMULATIVE_SUM() diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/drop.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/drop.md index 75a5e90bb..ac71f26af 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/drop.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/drop.md @@ -8,7 +8,7 @@ menu: v2_0_ref: name: drop parent: built-in-transformations -weight: 401 +weight: 402 --- The `drop()` function removes specified columns from a table. diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/duplicate.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/duplicate.md index cbc060dc0..db6a2ebc1 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/duplicate.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/duplicate.md @@ -8,7 +8,7 @@ menu: v2_0_ref: name: duplicate parent: built-in-transformations -weight: 401 +weight: 402 --- The `duplicate()` function duplicates a specified column in a table. diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/elapsed.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/elapsed.md index b297476c2..e4adcbc2e 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/elapsed.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/elapsed.md @@ -7,7 +7,7 @@ menu: v2_0_ref: name: elapsed parent: built-in-transformations -weight: 401 +weight: 402 --- The `elapsed()` function returns the time between subsequent records. diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/fill.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/fill.md index a0997656f..e3a3bf247 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/fill.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/fill.md @@ -8,7 +8,7 @@ menu: v2_0_ref: name: fill parent: built-in-transformations -weight: 401 +weight: 402 related: - /v2.0/query-data/flux/fill/ - https://docs.influxdata.com/influxdb/latest/query_language/data_exploration/#group-by-time-intervals-and-fill, InfluxQL – FILL diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/filter.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/filter.md index 5826b2023..50e77e6ff 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/filter.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/filter.md @@ -8,7 +8,7 @@ menu: v2_0_ref: name: filter parent: built-in-transformations -weight: 401 +weight: 402 v2.0/tags: [exists] related: - /v2.0/query-data/flux/query-fields/ diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/group.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/group.md index e0201f821..77fc61f9c 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/group.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/group.md @@ -8,7 +8,7 @@ menu: v2_0_ref: name: group parent: built-in-transformations -weight: 401 +weight: 402 related: - /v2.0/query-data/flux/group-data/ - https://docs.influxdata.com/influxdb/latest/query_language/data_exploration/#the-group-by-clause, InfluxQL – GROUP BY diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/histogram.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/histogram.md index cf0b839d5..7f9d43c39 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/histogram.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/histogram.md @@ -8,7 +8,7 @@ menu: v2_0_ref: name: histogram parent: built-in-transformations -weight: 401 +weight: 402 related: - /v2.0/query-data/flux/histograms/ --- diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/hourselection.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/hourselection.md index b56ad99f5..ee53fa130 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/hourselection.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/hourselection.md @@ -10,7 +10,7 @@ menu: v2_0_ref: name: hourSelection parent: built-in-transformations -weight: 401 +weight: 402 --- The `hourSelection()` function retains all rows with time values in a specified hour range. diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/join.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/join.md index 5d65d942a..cb4946451 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/join.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/join.md @@ -8,7 +8,7 @@ menu: v2_0_ref: name: join parent: built-in-transformations -weight: 401 +weight: 402 related: - /v2.0/query-data/flux/join/ - /v2.0/reference/flux/stdlib/built-in/transformations/union/ diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/keep.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/keep.md index 6c4f0dada..94c7e6d29 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/keep.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/keep.md @@ -8,7 +8,7 @@ menu: v2_0_ref: name: keep parent: built-in-transformations -weight: 401 +weight: 402 --- The `keep()` function returns a table containing only the specified columns, ignoring all others. diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/keys.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/keys.md index 21a34feb6..e7b604dcf 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/keys.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/keys.md @@ -11,7 +11,7 @@ menu: v2_0_ref: name: keys parent: built-in-transformations -weight: 401 +weight: 402 related: - https://docs.influxdata.com/influxdb/latest/query_language/schema_exploration/#show-measurements, InfluxQL – SHOW MEASUREMENTS - https://docs.influxdata.com/influxdb/latest/query_language/schema_exploration/#show-field-keys, InfluxQL – SHOW FIELD KEYS diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/keyvalues.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/keyvalues.md index 0dafff28e..147690368 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/keyvalues.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/keyvalues.md @@ -8,7 +8,7 @@ menu: v2_0_ref: name: keyValues parent: built-in-transformations -weight: 401 +weight: 402 related: - https://docs.influxdata.com/influxdb/latest/query_language/schema_exploration/#show-measurements, InfluxQL – SHOW MEASUREMENTS - https://docs.influxdata.com/influxdb/latest/query_language/schema_exploration/#show-field-keys, InfluxQL – SHOW FIELD KEYS diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/limit.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/limit.md index 6fb5f9db1..472386eca 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/limit.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/limit.md @@ -8,7 +8,7 @@ menu: v2_0_ref: name: limit parent: built-in-transformations -weight: 401 +weight: 402 related: - /v2.0/query-data/flux/sort-limit/ - /v2.0/reference/flux/stdlib/built-in/transformations/tail/ diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/map.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/map.md index dfe4dd628..5979b42d5 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/map.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/map.md @@ -8,7 +8,7 @@ menu: v2_0_ref: name: map parent: built-in-transformations -weight: 401 +weight: 402 v2.0/tags: [exists] related: - /v2.0/query-data/flux/conditional-logic/ diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/pivot.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/pivot.md index 422814428..b9f552a53 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/pivot.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/pivot.md @@ -8,7 +8,7 @@ menu: v2_0_ref: name: pivot parent: built-in-transformations -weight: 401 +weight: 402 --- The `pivot()` function collects values stored vertically (column-wise) in a table diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/range.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/range.md index 1a6ad098f..70360537f 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/range.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/range.md @@ -8,7 +8,7 @@ menu: v2_0_ref: name: range parent: built-in-transformations -weight: 401 +weight: 402 related: - https://docs.influxdata.com/influxdb/latest/query_language/data_exploration/#the-where-clause, InfluxQL – WHERE --- diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/rename.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/rename.md index 57e3c504f..8f34a8f0c 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/rename.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/rename.md @@ -8,7 +8,7 @@ menu: v2_0_ref: name: rename parent: built-in-transformations -weight: 401 +weight: 402 --- The `rename()` function renames specified columns in a table. diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/set.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/set.md index 812bc21b0..0354cbdf5 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/set.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/set.md @@ -8,7 +8,7 @@ menu: v2_0_ref: name: set parent: built-in-transformations -weight: 401 +weight: 402 --- The `set()` function assigns a static value to each record in the input table. diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/sort.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/sort.md index 9c64201b4..f3de134dd 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/sort.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/sort.md @@ -8,7 +8,7 @@ menu: v2_0_ref: name: sort parent: built-in-transformations -weight: 401 +weight: 402 related: - /v2.0/query-data/flux/sort-limit/ --- diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/statecount.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/statecount.md index 2b2e83ca7..0668b3948 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/statecount.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/statecount.md @@ -8,7 +8,7 @@ menu: v2_0_ref: name: stateCount parent: built-in-transformations -weight: 401 +weight: 402 related: - /v2.0/query-data/flux/monitor-states/ --- diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/stateduration.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/stateduration.md index f46f7ef13..8e2381741 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/stateduration.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/stateduration.md @@ -8,7 +8,7 @@ menu: v2_0_ref: name: stateDuration parent: built-in-transformations -weight: 401 +weight: 402 related: - /v2.0/query-data/flux/monitor-states/ --- diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/stream-table/_index.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/stream-table/_index.md index 688684818..f64bccad1 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/stream-table/_index.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/stream-table/_index.md @@ -20,11 +20,31 @@ related: 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 +{{< children type="functions" >}} + +### Example stream and table functions + +##### Recommended usage ```js data = from(bucket:"example-bucket") - |> range(start: -5m) - |> filter(fn:(r) => r._measurement == "cpu") + |> range(start: -5m) + |> filter(fn:(r) => r._measurement == "cpu") + +// Extract the "_value" column from the table +data + |> findColumn(fn: (key) => key._field == "usage_idle", column: "_value") + +// Extract the first record from the table +data + |> findRecord(fn: (key) => key._field == "usage_idle", idx: 0) + +``` + +##### Alternate usage +```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") @@ -35,5 +55,3 @@ 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/stdlib/built-in/transformations/stream-table/findcolumn.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/stream-table/findcolumn.md new file mode 100644 index 000000000..53310e3b8 --- /dev/null +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/stream-table/findcolumn.md @@ -0,0 +1,54 @@ +--- +title: findColumn() function +description: > + The `findColumn()` function returns an array of values in a specified column from the + first table in a stream of tables where group key values match the specified predicate. +menu: + v2_0_ref: + name: findColumn + parent: Stream & table +weight: 501 +related: + - /v2.0/query-data/flux/scalar-values/ +--- + +The `findColumn()` function returns an array of values in a specified column from the +first table in a stream of tables where the group key values match the specified predicate. +The function returns an empty array if no table is found or if the column label +is not present in the set of columns. + +_**Function type:** Stream and table_ + +```js +findColumn( + fn: (key) => key._field == "fieldName") + column: "_value" +) +``` + +## Parameters + +### fn +A predicate function for matching keys in a table's group key. +Expects a `key` argument that represents a group key in the input stream. + +_**Data type:** Function_ + +### column +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") + |> findColumn( + fn: (key) => key._field == "usage_idle", + column: "_value" + ) + +// Use column values +x = vs[0] + vs[1] +``` diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/stream-table/findrecord.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/stream-table/findrecord.md new file mode 100644 index 000000000..edf2f8a56 --- /dev/null +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/stream-table/findrecord.md @@ -0,0 +1,54 @@ +--- +title: findRecord() function +description: > + The `findRecord()` function returns a record at a specified index from the first + table in a stream of tables where the group key values match the specified predicate. +menu: + v2_0_ref: + name: findRecord + parent: Stream & table +weight: 501 +related: + - /v2.0/query-data/flux/scalar-values/ +--- + +The `findRecord()` function returns a record at a specified index from the first +table in a stream of tables where the group key values match the specified predicate. +The function returns an empty object if no table is found or if the index is out of bounds. + +_**Function type:** Stream and table_ + +```js +findRecord( + fn: (key) => key._field == "fieldName", + idx: 0 +) +``` + +## Parameters + +### fn +A predicate function for matching keys in a table's group key. +Expects a `key` argument that represents a group key in the input stream. + +_**Data type:** Function_ + +### idx +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() + |> findRecord( + fn: (key) => key._field == "usage_idle", + idx: 0 + ) + +// Use record values +x = r0._field + "--" + r0._measurement +``` diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/stream-table/getcolumn.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/stream-table/getcolumn.md index 0eb8864ac..37ee22574 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/stream-table/getcolumn.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/stream-table/getcolumn.md @@ -33,7 +33,7 @@ to extract a single table from a stream of tables. ## Parameters ### column -The name of the column to extract. +Name of the column to extract. _**Data type:** String_ diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/stream-table/getrecord.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/stream-table/getrecord.md index 6aa31318f..5ac41aa20 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/stream-table/getrecord.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/stream-table/getrecord.md @@ -33,7 +33,7 @@ to extract a single table from a stream of tables. ## Parameters ### idx -The index of the record to extract. +Index of the record to extract. _**Data type:** Integer_ diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/stream-table/tablefind.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/stream-table/tablefind.md index 14c5c8519..4644e1ad6 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/stream-table/tablefind.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/stream-table/tablefind.md @@ -34,7 +34,7 @@ To learn why, see [Match parameter names](/v2.0/reference/flux/language/data-mod 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. +Expects a `key` argument that represents a group key in the input stream. _**Data type:** Function_ diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/tail.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/tail.md index b86287b1b..fe975298e 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/tail.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/tail.md @@ -7,7 +7,7 @@ menu: v2_0_ref: name: tail parent: built-in-transformations -weight: 401 +weight: 402 related: - /v2.0/reference/flux/functions/built-in/transformations/limit/ --- diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/timeshift.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/timeshift.md index be365a397..624fe3b8a 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/timeshift.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/timeshift.md @@ -9,7 +9,7 @@ menu: v2_0_ref: name: timeShift parent: built-in-transformations -weight: 401 +weight: 402 --- The `timeShift()` function adds a fixed duration to time columns. diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/truncatetimecolumn.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/truncatetimecolumn.md index 6b0a0b053..63df2ba40 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/truncatetimecolumn.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/truncatetimecolumn.md @@ -8,7 +8,7 @@ menu: v2_0_ref: name: truncateTimeColumn parent: built-in-transformations -weight: 401 +weight: 402 related: - /v2.0/reference/flux/stdlib/date/truncate/ --- diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/union.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/union.md index f2ed1030a..529bc546e 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/union.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/union.md @@ -8,7 +8,7 @@ menu: v2_0_ref: name: union parent: built-in-transformations -weight: 401 +weight: 402 related: - /v2.0/reference/flux/stdlib/built-in/transformations/join/ --- diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/window.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/window.md index 9c72e0b1b..b663bfc50 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/window.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/window.md @@ -8,7 +8,7 @@ menu: v2_0_ref: name: window parent: built-in-transformations -weight: 401 +weight: 402 related: - /v2.0/query-data/flux/window-aggregate/ - https://docs.influxdata.com/influxdb/latest/query_language/data_exploration/#the-group-by-clause, InfluxQL – GROUP BY time()