findRecord() function

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 record if no table is found or if the index is out of bounds.

*Function type: Stream and table*

  1. findRecord(
  2. fn: (key) => key._field == "fieldName",
  3. idx: 0
  4. )

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

  1. r0 = from(bucket:"example-bucket")
  2. |> range(start: -5m)
  3. |> filter(fn:(r) => r._measurement == "cpu")
  4. |> tableFind()
  5. |> findRecord(
  6. fn: (key) => key._field == "usage_idle",
  7. idx: 0
  8. )
  9. // Use record values
  10. x = r0._field + "--" + r0._measurement

Related articles