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

3.2 KiB
Raw Permalink Blame History

title description aliases menu weight flux/v0.x/tags related introduced
distinct() function The `distinct()` function returns the unique values for a given column.
/influxdb/v2.0/reference/flux/functions/transformations/selectors/distinct
/influxdb/v2.0/reference/flux/functions/built-in/transformations/selectors/distinct/
/influxdb/v2.0/reference/flux/stdlib/built-in/transformations/selectors/distinct/
/influxdb/cloud/reference/flux/stdlib/built-in/transformations/selectors/distinct/
flux_0_x_ref
name parent
distinct universe
102
selectors
transformations
/{{< latest "influxdb" "v1" >}}/query_language/functions/#distinct, InfluxQL  DISTINCT()
0.7.0

The distinct() function returns the unique values for a given column. The _value of each output record is set to the distinct value in the specified column. null is considered its own distinct value if it is present. distinct() is a selector function.

distinct(column: "host")

{{% warn %}}

Empty tables

distinct() drops empty tables. {{% /warn %}}

Parameters

column

Column to return unique values from. Default is _value.

tables

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

Examples

{{% flux/sample-example-intro plural=true %}}

Return distinct values from the _value column

import "sampledata"

data = sampledata.int()

data
    |> distinct()

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

Input data

{{% flux/sample set="int" %}}

{{% /flex-content %}} {{% flex-content %}}

Output data
tag _value
t1 -2
t1 10
t1 7
t1 17
t1 15
t1 4
tag _value
t2 19
t2 4
t2 -3
t2 13
t2 1

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

Return distinct values from a non-default column

import "sampledata"

sampledata.int()
    |> distinct(column: "tag")

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

Input data

{{% flux/sample set="int" %}}

{{% /flex-content %}} {{% flex-content %}}

Output data
tag _value
t1 t1
tag _value
t2 t2

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

Return distinct values from with null values

import "sampledata"

sampledata.int(includeNull: true)
    |> distinct()

{{% expand "View input and output" %}} {{< flex >}} {{% flex-content %}}

Input data

{{% flux/sample "int" true %}}

{{% /flex-content %}} {{% flex-content %}}

Output data
tag _value
t1 -2
t1
t1 7
t1 4
tag _value
t2
t2 4
t2 -3
t2 19
t2 1

{{% /flex-content %}} {{< /flex >}} {{% /expand %}}