4.7 KiB
title | description | aliases | menu | weight | flux/v0.x/tags | introduced | related | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
toInt() function | The `toInt()` function converts all values in the `_value` column to integers. |
|
|
102 |
|
0.7.0 |
|
The toInt()
function converts all values in the _value
column to integers.
toInt()
Supported data types
- bool
- duration
- float
- string (numeric)
- time
- uinteger
toInt()
behavior depends on the _value
column data type:
_value type | Returned value |
---|---|
string | Integer equivalent of the numeric string |
bool | 1 (true) or 0 (false) |
duration | Number of nanoseconds in the specified duration |
time | Equivalent nanosecond epoch timestamp |
float | Value truncated at the decimal |
uint | Integer equivalent of the unsigned integer |
{{% 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 %}}
Parameters
tables
Input data.
Default is piped-forward data (<-
).
Examples
{{% flux/sample-example-intro plural=true %}}
- Convert a float value column to an integer column
- Convert a boolean value column to an integer column
- Convert a uinteger value column to an integer column
Convert a float value column to an integer column
import "sampledata"
sampledata.float()
|> toInt()
{{< expand-wrapper >}} {{% expand "View input and output" %}} {{< flex >}} {{% flex-content %}}
Input data
{{% flux/sample "float" %}}
{{% /flex-content %}} {{% flex-content %}}
Output data
_time | tag | _value |
---|---|---|
2021-01-01T00:00:00Z | t1 | -2 |
2021-01-01T00:00:10Z | t1 | 10 |
2021-01-01T00:00:20Z | t1 | 7 |
2021-01-01T00:00:30Z | t1 | 17 |
2021-01-01T00:00:40Z | t1 | 15 |
2021-01-01T00:00:50Z | t1 | 4 |
_time | tag | _value |
---|---|---|
2021-01-01T00:00:00Z | t2 | 19 |
2021-01-01T00:00:10Z | t2 | 4 |
2021-01-01T00:00:20Z | t2 | -3 |
2021-01-01T00:00:30Z | t2 | 19 |
2021-01-01T00:00:40Z | t2 | 13 |
2021-01-01T00:00:50Z | t2 | 1 |
{{% /flex-content %}} | ||
{{< /flex >}} | ||
{{% /expand %}} | ||
{{< /expand-wrapper >}} |
Convert a boolean value column to an integer column
import "sampledata"
sampledata.bool()
|> toInt()
{{< expand-wrapper >}} {{% expand "View input and output" %}} {{< flex >}} {{% flex-content %}}
Input data
{{% flux/sample "bool" %}}
{{% /flex-content %}} {{% flex-content %}}
Output data
{{% flux/sample "numericBool" %}}
{{% /flex-content %}} {{< /flex >}} {{% /expand %}} {{< /expand-wrapper >}}
Convert a uinteger value column to an integer column
import "sampledata"
sampledata.uint()
|> toInt()
{{< expand-wrapper >}} {{% expand "View input and output" %}} {{< flex >}} {{% flex-content %}}
Input data
{{% flux/sample "uint" %}}
{{% /flex-content %}} {{% flex-content %}}
Output data
_time | tag | _value |
---|---|---|
2021-01-01T00:00:00Z | t1 | -2 |
2021-01-01T00:00:10Z | t1 | 10 |
2021-01-01T00:00:20Z | t1 | 7 |
2021-01-01T00:00:30Z | t1 | 17 |
2021-01-01T00:00:40Z | t1 | 15 |
2021-01-01T00:00:50Z | t1 | 4 |
_time | tag | _value |
---|---|---|
2021-01-01T00:00:00Z | t2 | 19 |
2021-01-01T00:00:10Z | t2 | 4 |
2021-01-01T00:00:20Z | t2 | -3 |
2021-01-01T00:00:30Z | t2 | 19 |
2021-01-01T00:00:40Z | t2 | 13 |
2021-01-01T00:00:50Z | t2 | 1 |
{{% /flex-content %}} | ||
{{< /flex >}} | ||
{{% /expand %}} | ||
{{< /expand-wrapper >}} |