docs-v2/content/flux/v0/stdlib/universe/tobool.md

3.1 KiB

title description menu weight flux/v0/tags introduced
toBool() function `toBool()` converts all values in the `_value` column to boolean types.
flux_v0_ref
name parent identifier
toBool universe universe/toBool
101
transformations
type-conversions
0.7.0

toBool() converts all values in the _value column to boolean types.

Supported data types

  • string: true or false
  • int: 1 or 0
  • uint: 1 or 0
  • float: 1.0 or 0.0
Function type signature
(<-tables: stream[{A with _value: B}]) => stream[{A with _value: B, _value: bool}]

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

Parameters

tables

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

Examples

Convert an integer _value column to booleans

import "sampledata"

sampledata.numericBool()
    |> toBool()

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

Input data

_time _value *tag
2021-01-01T00:00:00Z 1 t1
2021-01-01T00:00:10Z 1 t1
2021-01-01T00:00:20Z 0 t1
2021-01-01T00:00:30Z 1 t1
2021-01-01T00:00:40Z 0 t1
2021-01-01T00:00:50Z 0 t1
_time _value *tag
2021-01-01T00:00:00Z 0 t2
2021-01-01T00:00:10Z 1 t2
2021-01-01T00:00:20Z 0 t2
2021-01-01T00:00:30Z 1 t2
2021-01-01T00:00:40Z 1 t2
2021-01-01T00:00:50Z 0 t2

Output data

_time _value *tag
2021-01-01T00:00:00Z true t1
2021-01-01T00:00:10Z true t1
2021-01-01T00:00:20Z false t1
2021-01-01T00:00:30Z true t1
2021-01-01T00:00:40Z false t1
2021-01-01T00:00:50Z false t1
_time _value *tag
2021-01-01T00:00:00Z false t2
2021-01-01T00:00:10Z true t2
2021-01-01T00:00:20Z false t2
2021-01-01T00:00:30Z true t2
2021-01-01T00:00:40Z true t2
2021-01-01T00:00:50Z false t2

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