处理 Null 类型
Null 类型 表示缺失值或未知值。
类型名称: null
Null 语法
Null 类型存在于其他基本类型的列中。Flux 不为 null 值提供字面语法,但是,您可以使用 debug.null()
返回指定类型的 null 值。
import "internal/debug"
// Return a null string
debug.null(type: "string")
// Return a null integer
debug.null(type: "int")
// Return a null boolean
debug.null(type: "bool")
空字符串 (""
) 不是 null 值。
检查列值是否为 null
在迭代行的函数(例如 filter()
或 map()
)中,使用 exists
逻辑运算符 检查列值是否为 null。
过滤掉具有 null 值的行
data
|> filter(fn: (r) => exists r._value)
给定以下输入数据
_time | _value |
---|---|
2021-01-01T00:00:00Z | 1.2 |
2021-01-01T02:00:00Z | |
2021-01-01T03:00:00Z | 2.5 |
2021-01-01T04:00:00Z |
上面的示例返回
_time | _value |
---|---|
2021-01-01T00:00:00Z | 1.2 |
2021-01-01T03:00:00Z | 2.5 |
在表的特别数据流中包含 null 值
- 使用
array.from()
创建表的特别数据流。 - 使用
debug.null()
包含 null 列值。
import "array"
import "internal/debug"
array.from(
rows: [
{a: 1, b: 2, c: 3, d: "four"},
{a: debug.null(type: "int"), b: 5, c: 6, d: debug.null(type: "string")}
]
)
上面的示例返回
a | b | c | d |
---|---|---|---|
1 | 2 | 3 | four |
5 | 6 |
此页面是否对您有帮助?
感谢您的反馈!