types.isType() 函数
types.isType() 测试一个值是否是指定的类型。
函数类型签名
(type: string, v: A) => bool where A: Basic
有关更多信息,请参见 Function type signatures。
参数
v
(必需) 测试的值。
类型
(必需) 描述要检查的类型的字符串。
支持的类型:
- 字符串
- 字节
- 整数
- uint
- 浮点数
- bool
- 时间
- 持续时间
- regexp
示例
按值类型过滤
import "types"
data
|> filter(fn: (r) => types.isType(v: r._value, type: "string"))
根据类型汇总或选择数据
import "types"
nonNumericData =
data
|> filter(
fn: (r) =>
types.isType(v: r._value, type: "string") or types.isType(
v: r._value,
type: "bool",
),
)
|> aggregateWindow(every: 30s, fn: last)
numericData =
data
|> filter(
fn: (r) =>
types.isType(v: r._value, type: "int") or types.isType(v: r._value, type: "float"),
)
|> aggregateWindow(every: 30s, fn: mean)
union(tables: [nonNumericData, numericData])