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

2.4 KiB

title description aliases menu weight flux/v0.x/tags related introduced
toBool() function The `toBool()` function converts all values in the `_value` column to booleans.
/influxdb/v2.0/reference/flux/functions/transformations/type-conversions/tobool
/influxdb/v2.0/reference/flux/functions/built-in/transformations/type-conversions/tobool/
/influxdb/v2.0/reference/flux/stdlib/built-in/transformations/type-conversions/tobool/
/influxdb/cloud/reference/flux/stdlib/built-in/transformations/type-conversions/tobool/
flux_0_x_ref
name parent
toBool universe
102
type-conversions
transformations
/flux/v0.x/data-types/basic/bool/
/flux/v0.x/stdlib/universe/bool/
0.7.0

The toBool() function converts all values in the _value column to booleans.

toBool()

{{% note %}} To convert values in a column other than _value, define a custom function patterned after the function definition, but replace _value with your desired column. {{% /note %}}

Supported data types
  • string: true or false
  • int: 1 or 0
  • uint: 1 or 0
  • float: 1.0 or 0.0

Parameters

tables

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

Examples

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

Convert an integer value column to a boolean column

import "sampledata"

sampledata.numericBool()
    |> toBool()

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

Input data

{{% flux/sample "numericBool" %}}

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

Output data
_time tag _value
2021-01-01T00:00:00Z t1 true
2021-01-01T00:00:10Z t1 true
2021-01-01T00:00:20Z t1 false
2021-01-01T00:00:30Z t1 true
2021-01-01T00:00:40Z t1 false
2021-01-01T00:00:50Z t1 false
_time tag _value
2021-01-01T00:00:00Z t2 false
2021-01-01T00:00:10Z t2 true
2021-01-01T00:00:20Z t2 false
2021-01-01T00:00:30Z t2 true
2021-01-01T00:00:40Z t2 true
2021-01-01T00:00:50Z t2 false
{{% /flex-content %}}
{{< /flex >}}
{{% /expand %}}
{{< /expand-wrapper >}}