InfluxDB: Flux - Distinct() vs. Unique(): Unterschied zwischen den Versionen
Aus Wiki-WebPerfect
Admin (Diskussion | Beiträge) K |
Admin (Diskussion | Beiträge) |
||
Zeile 31: | Zeile 31: | ||
''The distinct() function '''returns the unique values for a given column'''. Null is considered its own distinct value if it is present. Distinct() is a selector function.'' <br> | ''The distinct() function '''returns the unique values for a given column'''. Null is considered its own distinct value if it is present. Distinct() is a selector function.'' <br> | ||
The function [https://docs.influxdata.com/flux/v0.x/stdlib/universe/distinct/ distinct()] by default uses the column ''_value''. <br> | The function [https://docs.influxdata.com/flux/v0.x/stdlib/universe/distinct/ distinct()] by default uses the column ''_value''. <br> | ||
− | So if you use distinct() without parameters | + | So if you use distinct() without parameters like following query: <br> |
− | + | ||
<pre> | <pre> | ||
.. | .. | ||
− | |||
array.from(rows: var) | array.from(rows: var) | ||
|> distinct() | |> distinct() | ||
</pre> | </pre> | ||
+ | |||
+ | '''Output''' | ||
+ | [[Datei:02-distinct without parameter.png]] <br> | ||
+ | |||
This means following will be removed: <br> | This means following will be removed: <br> |
Version vom 10. Dezember 2021, 09:41 Uhr
Because I was confused several times about which function is the right one (distinct() or unique()) I write this site.
Inhaltsverzeichnis
Base Data
All the the examples from this site are based from the following data:
Flux query to generate this data
import "array" var = [ {_time: time(v: "2021-12-10T00:01:00Z"), host: "HOST01", _field: "cpu_usage", _value: 37}, {_time: time(v: "2021-12-10T00:02:00Z"), host: "HOST02", _field: "cpu_usage", _value: 72}, {_time: time(v: "2021-12-10T00:03:00Z"), host: "HOST03", _field: "cpu_usage", _value: 88}, {_time: time(v: "2021-12-10T00:04:00Z"), host: "HOST03", _field: "cpu_usage", _value: 11}, {_time: time(v: "2021-12-10T00:05:00Z"), host: "HOST01", _field: "cpu_usage", _value: 37}, {_time: time(v: "2021-12-10T00:06:00Z"), host: "HOST02", _field: "cpu_usage", _value: 90}, {_time: time(v: "2021-12-10T00:07:00Z"), host: "HOST04", _field: "cpu_usage", _value: 90}, {_time: time(v: "2021-12-10T00:08:00Z"), host: "HOST03", _field: "cpu_usage", _value: 77}, {_time: time(v: "2021-12-10T00:09:00Z"), host: "HOST05", _field: "cpu_usage", _value: 57}, {_time: time(v: "2021-12-10T00:10:00Z"), host: "HOST01", _field: "cpu_usage", _value: 13} ] array.from(rows: var)
Distinct()
The distinct() function returns the unique values for a given column. Null is considered its own distinct value if it is present. Distinct() is a selector function.
The function distinct() by default uses the column _value.
So if you use distinct() without parameters like following query:
.. array.from(rows: var) |> distinct()
This means following will be removed: