杂项 SQL 函数
InfluxDB 集群 SQL 实现支持以下杂项功能,以执行多种操作:
箭头转换
将值转换为特定的Arrow数据类型。
arrow_cast(expression, datatype)
参数
- expression: 要转换的表达式。
可以是常量、列或函数,以及任意组合的算术或字符串运算符。
- datatype: Arrow 数据类型 要转换为。
查看 arrow_cast
查询示例
以下示例使用在 开始使用InfluxDB教程 中提供的示例数据集。
SELECT
arrow_cast(time, 'Int64') AS time,
arrow_cast(temp, 'Utf8') AS temp,
arrow_cast(co, 'Float64')AS co
FROM home
LIMIT 1
时间 | 温度 | 一氧化碳 |
---|
1641024000000000000 | 21.0 | 0 |
箭头类型
返回表达式的基础 Arrow 数据类型:
参数
- expression: 要评估的表达式。 可以是常量、列或函数,以及任何算术或字符串运算符的组合。
查看 arrow_typeof
查询示例
以下示例使用在 开始使用InfluxDB教程 中提供的示例数据集。
SELECT
arrow_typeof(time) AS time,
arrow_typeof(room) AS room,
arrow_typeof(temp) AS temp,
arrow_typeof(co) AS co
FROM home
LIMIT 1
时间 | 房间 | 温度 | 二氧化碳 |
---|
时间戳(纳秒, 无) | 字典(整型,Utf8) | 双精度浮点数 | 整型 |
插值
通过从现有值中插值填充指定聚合列中的空值。 必须与 date_bin_gapfill
一起使用。
interpolate(aggregate_expression)
参数
- aggregate_expression: 对指定表达式的聚合操作。
该操作可以使用任何aggregate function。
表达式可以是常量、列或函数,以及聚合函数支持的算术运算符的任何组合。
date_bin_gapfill,
locf
查看 interpolate
查询示例
以下示例使用在开始使用InfluxDB教程中提供的示例数据集。
SELECT
date_bin_gapfill(INTERVAL '30 minutes', time) as _time,
room,
interpolate(avg(temp))
FROM home
WHERE
time >= '2022-01-01T08:00:00Z'
AND time <= '2022-01-01T10:00:00Z'
GROUP BY _time, room
时间 | 房间 | 平均(家里温度) |
---|
2022-01-01T08:00:00Z | 厨房 | 21 |
2022-01-01T08:30:00Z | 厨房 | 22 |
2022-01-01T09:00:00Z | 厨房 | 23 |
2022-01-01T09:30:00Z | 厨房 | 22.85 |
2022-01-01T10:00:00Z | 厨房 | 22.7 |
2022-01-01T08:00:00Z | 客厅 | 21.1 |
2022-01-01T08:30:00Z | 客厅 | 21.25 |
2022-01-01T09:00:00Z | 客厅 | 21.4 |
2022-01-01T09:30:00Z | 客厅 | 21.6 |
2022-01-01T10:00:00Z | 客厅 | 21.8 |
最近观测值填充(locf)
通过向前填充最后观察到的值来填充指定聚合列中的空值。 必须与 date_bin_gapfill
一起使用。
LOCF是“最后观察延续”的首字母缩略词。
locf(aggregate_expression)
参数
- aggregate_expression: 对指定表达式的聚合操作。
该操作可以使用任何aggregate function。
表达式可以是常量、列或函数,以及聚合函数支持的算术运算符的任何组合。
date_bin_gapfill,
interpolate
查看 locf
查询示例
以下示例使用在开始使用InfluxDB教程中提供的示例数据集。
SELECT
date_bin_gapfill(INTERVAL '30 minutes', time) as _time,
room,
locf(avg(temp))
FROM home
WHERE
time >= '2022-01-01T08:00:00Z'
AND time <= '2022-01-01T10:00:00Z'
GROUP BY _time, room
时间 | 房间 | 平均(家里温度) |
---|
2022-01-01T08:00:00Z | 厨房 | 21 |
2022-01-01T08:30:00Z | 厨房 | 21 |
2022-01-01T09:00:00Z | 厨房 | 23 |
2022-01-01T09:30:00Z | 厨房 | 23 |
2022-01-01T10:00:00Z | 厨房 | 22.7 |
2022-01-01T08:00:00Z | 客厅 | 21.1 |
2022-01-01T08:30:00Z | 客厅 | 21.1 |
2022-01-01T09:00:00Z | 客厅 | 21.4 |
2022-01-01T09:30:00Z | 客厅 | 21.4 |
2022-01-01T10:00:00Z | 客厅 | 21.8 |