filter() 函数
filter()
函数根据谓词函数 (fn
) 中定义的条件过滤数据。
输出表与相应的输入表具有相同的模式。
函数类型签名
(<-tables: stream[A], fn: (r: A) => bool, ?onEmpty: string) => stream[A] where A: Record
有关更多信息,请参阅 函数类型签名。
参数
fn
(必需) 计算结果为 true
或 false
的单参数谓词函数。
表示每行的记录作为 r
传递给函数。计算结果为 true
的记录包含在输出表中。计算结果为 null 或 false
的记录将从输出表中排除。
onEmpty
空表时采取的操作。默认为 drop
。
支持的值:
- keep: 保留空表。
- drop: 删除空表。
tables
输入数据。默认为管道转发数据 (<-
)。
示例
根据 InfluxDB 测量、字段和标签进行过滤
from(bucket: "example-bucket")
|> range(start: -1h)
|> filter(
fn: (r) => r._measurement == "cpu" and r._field == "usage_system" and r.cpu == "cpu-total",
)
过滤时保留空表
import "sampledata"
import "experimental/table"
sampledata.int()
|> filter(fn: (r) => r._value > 18, onEmpty: "keep")
根据阈值过滤值
import "sampledata"
sampledata.int()
|> filter(fn: (r) => r._value > 0 and r._value < 10)
此页是否对您有帮助?
感谢您的反馈!