3.6 KiB
3.6 KiB
title | description | menu | weight | flux/v0/tags | introduced | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
bool() function | `bool()` converts a value to a boolean type. |
|
101 |
|
0.7.0 |
bool()
converts a value to a boolean type.
Function type signature
(v: A) => bool
{{% caption %}} For more information, see Function type signatures. {{% /caption %}}
Parameters
v
({{< req >}}) Value to convert.
Examples
- Convert strings to booleans
- Convert numeric values to booleans
- Convert all values in a column to booleans
Convert strings to booleans
bool(v: "true")
// Returns true
bool(v: "false")// Returns false
Convert numeric values to booleans
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.
data
|> map(fn: (r) => ({r with powerOn: bool(v: r.powerOn)}))
{{< expand-wrapper >}} {{% expand "View example input and output" %}}
Input data
_time | powerOn | *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 | powerOn | *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 | powerOn | *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 | powerOn | *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 >}}