2.1 KiB
2.1 KiB
title | description | menu | weight | ||||||
---|---|---|---|---|---|---|---|---|---|
Flux reference documentation | Learn the Flux syntax and structure used to query InfluxDB. |
|
103 |
All Flux reference material is provided in the Flux documentation:
Flux with the InfluxDB IOx storage engine
When querying data from an InfluxDB bucket powered by InfluxDB IOx, use the following input functions:
iox.from()
: alternative tofrom()
.iox.sql()
: execute a SQL query with Flux.
Both IOx-based input functions return pivoted data with a column for each field in the output. To unpivot the data:
- Group by tag columns.
- Rename the
time
column to_time
. - Use
experimental.unpivot()
to unpivot the data. All columns not in the group key (other than_time
) are treated as fields.
{{< code-tabs-wrapper >}} {{% code-tabs %}} iox.from() iox.sql() {{% /code-tabs %}} {{% code-tab-content %}}
import "experimental"
import "experimental/iox"
iox.from(bucket: "example-bucket", measurement: "example-measurement")
|> range(start: -1d)
|> group(columns: ["tag1", "tag2". "tag3"])
|> rename(columns: {time: "_time_"})
|> experimental.unpivot()
{{% /code-tab-content %}} {{% code-tab-content %}}
import "experimental"
import "experimental/iox"
query = "SELECT * FROM \"example-measurement\" WHERE time >= now() - INTERVAL '1 day'"
iox.sql(bucket: "example-bucket", query: query)
|> group(columns: ["tag1", "tag2". "tag3"])
|> rename(columns: {time: "_time_"})
|> experimental.unpivot()
{{% /code-tab-content %}} {{< /code-tabs-wrapper >}}
{{% warn %}}
Flux performance with InfluxDB IOx
When querying data from an InfluxDB bucket powered by InfluxDB IOx, using iox.from()
is less performant than querying a TSM-powered bucket with from()
.
For better Flux query performance, use iox.sql()
.
{{% /warn %}}