Back to Influxdb

bool() function

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

latest3.4 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#L3142-L3142 Contributing to Flux: https://github.com/influxdata/flux#contributing Fluxdoc syntax: https://github.com/influxdata/flux/blob/master/docs/fluxdoc.md ------------------------------------------------------------------------------->

bool() converts a value to a boolean type.

Function type signature
js
(v: A) => bool

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

Parameters

v

({{< req >}}) Value to convert.

Examples

Convert strings to booleans

js
bool(v: "true")

// Returns true
bool(v: "false")// Returns false


Convert numeric values to booleans

js
bool(v: 1.0)

// Returns true
bool(v: 0.0)

// Returns false
bool(v: 1)

// Returns true
bool(v: 0)

// Returns false
bool(v: uint(v: 1))

// Returns true
bool(v: uint(v: 0))// Returns false


Convert all values in a column to booleans

If converting the _value column to boolean types, use toBool(). If converting columns other than _value, use map() to iterate over each row and bool() to convert a column value to a boolean type.

js
data
    |> map(fn: (r) => ({r with powerOn: bool(v: r.powerOn)}))

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

Input data

_timepowerOn*tag
2021-01-01T00:00:00Z1t1
2021-01-01T00:00:10Z1t1
2021-01-01T00:00:20Z0t1
2021-01-01T00:00:30Z1t1
2021-01-01T00:00:40Z0t1
2021-01-01T00:00:50Z0t1
_timepowerOn*tag
2021-01-01T00:00:00Z0t2
2021-01-01T00:00:10Z1t2
2021-01-01T00:00:20Z0t2
2021-01-01T00:00:30Z1t2
2021-01-01T00:00:40Z1t2
2021-01-01T00:00:50Z0t2

Output data

_timepowerOn*tag
2021-01-01T00:00:00Ztruet1
2021-01-01T00:00:10Ztruet1
2021-01-01T00:00:20Zfalset1
2021-01-01T00:00:30Ztruet1
2021-01-01T00:00:40Zfalset1
2021-01-01T00:00:50Zfalset1
_timepowerOn*tag
2021-01-01T00:00:00Zfalset2
2021-01-01T00:00:10Ztruet2
2021-01-01T00:00:20Zfalset2
2021-01-01T00:00:30Ztruet2
2021-01-01T00:00:40Ztruet2
2021-01-01T00:00:50Zfalset2

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