docs-v2/content/flux/v0.x/stdlib/universe/findrecord.md

1.5 KiB

title description aliases menu weight flux/v0.x/tags related introduced
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.
/influxdb/v2.0/reference/flux/stdlib/built-in/transformations/stream-table/findrecord/
/influxdb/cloud/reference/flux/stdlib/built-in/transformations/stream-table/findrecord/
flux_0_x_ref
name parent
findRecord universe
102
dynamic queries
/{{< latest "influxdb" >}}/query-data/flux/scalar-values/
0.68.0

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.

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.

idx

Index of the record to extract.

tables

Input data. Default is piped-forward data (<-).

Example

{{% flux/sample-example-intro %}}

import "sampledata"

sampledata.int()
    |> findRecord(fn: (key) => key.tag == "t1", idx: 0)
    
// Returns {_time: 2021-01-01T00:00:00.000000000Z, _value: -2, tag: t1}