Back to Influxdb

contains() function

content/flux/v0/stdlib/universe/contains.md

latest4.3 KB
Original Source
<!------------------------------------------------------------------------------ IMPORTANT: This page was generated from comments in the Flux source code. Any edits made directly to this page will be overwritten the next time the documentation is generated. To make updates to this documentation, update the function comments above the function definition in the Flux source code: https://github.com/influxdata/flux/blob/master/stdlib/universe/universe.flux#L3565-L3565 Contributing to Flux: https://github.com/influxdata/flux#contributing Fluxdoc syntax: https://github.com/influxdata/flux/blob/master/docs/fluxdoc.md ------------------------------------------------------------------------------->

contains() tests if an array contains a specified value and returns true or false.

Function type signature
js
(set: [A], value: A) => bool where A: Nullable

{{% caption %}} For more information, see Function type signatures. {{% /caption %}}

Parameters

value

({{< req >}}) Value to search for.

set

({{< req >}}) Array to search.

Examples

Filter on a set of specific fields

js
fields = ["f1", "f2"]

data
    |> filter(fn: (r) => contains(value: r._field, set: fields))

{{< expand-wrapper >}} {{% expand "View example input and output" %}}

Input data

_time_value*tag*_field_measurement
2021-01-01T00:00:00Z-2t1f1m
2021-01-01T00:00:50Z4t1f1m
_time_value*tag_measurement*_field
_time_value*tag_measurement*_field
2021-01-01T00:00:10Z4t2mf1
2021-01-01T00:00:20Z-3t2mf1
2021-01-01T00:00:50Z1t2mf1
_time_value*tag*_field_measurement
_time_value*tag*_field_measurement
2021-01-01T00:00:10Z10t1f2m
2021-01-01T00:00:20Z7t1f2m
_time_value*tag*_field_measurement
2021-01-01T00:00:30Z17t1f3m
2021-01-01T00:00:40Z15t1f3m
_time_value*tag_measurement*_field
_time_value*tag_measurement*_field
2021-01-01T00:00:00Z19t2mf3
2021-01-01T00:00:30Z19t2mf3
2021-01-01T00:00:40Z13t2mf3

Output data

_time_value*tag*_field_measurement
2021-01-01T00:00:00Z-2t1f1m
2021-01-01T00:00:50Z4t1f1m
_time_value*tag_measurement*_field
_time_value*tag_measurement*_field
2021-01-01T00:00:10Z4t2mf1
2021-01-01T00:00:20Z-3t2mf1
2021-01-01T00:00:50Z1t2mf1
_time_value*tag*_field_measurement
_time_value*tag*_field_measurement
2021-01-01T00:00:10Z10t1f2m
2021-01-01T00:00:20Z7t1f2m

{{% /expand %}} {{< /expand-wrapper >}}