我有一个测量数据由telegraf收集。它的结构如下:
名称: smart_device
fieldKey fieldType
-------- ---------
exit_status integer
health_ok boolean
read_error_rate integer
seek_error_rate integer
temp_c integer
udma_crc_errors integer当我查询这个数据库时,我可以这样做:
> select * from smart_device where "health_ok" = true limit 1
name: smart_device
time capacity device enabled exit_status health_ok host model read_error_rate seek_error_rate serial_no temp_c udma_crc_errors wwn
---- -------- ------ ------- ----------- --------- ---- ----- --------------- --------------- --------- ------ --------------- ---
15337409500 2000398934016 sda Enabled 0 true osd21 Hitachi HDS722020ALA330 0 0 JK11A4B8JR2EGW 38 0 5000cca222e6384f这是:
> select * from smart_device limit 1
name: smart_device
time capacity device enabled exit_status health_ok host model read_error_rate seek_error_rate serial_no temp_c udma_crc_errors wwn
---- -------- ------ ------- ----------- --------- ---- ----- --------------- --------------- --------- ------ --------------- ---
1533046990 sda 0 osd21 但是,当我尝试用空health_ok过滤掉记录时,我得到的输出是空的:
> select * from smart_device where "health_ok"!= true
> 如何选择空度量值(否)?(空?) health_ok
发布于 2018-08-11 11:43:35
不幸的是,目前无法使用InfluxQL进行此操作。InfluxDB是一种面向文档的数据库形式;它意味着度量的行可以有不同的模式。因此,对于行的字段没有null的概念;实际上此行没有该字段。例如,假设度量成本中有4行
> select * from cost
name: cost
time isok type value
---- ---- ---- -----
1533970927859614000 true 1 100
1533970938243629700 true 2 101
1533970949371761100 3 103
1533970961571703900 2 104如您所见,有两行带有isok=true,两行没有名为isok的字段;因此只有一种方法可以使用此查询选择具有isok字段的行的时间:
> select isok from cost
name: cost
time isok
---- ----
1533970927859614000 true
1533970938243629700 true由于InfluxQL当前不支持where子句中的子查询,因此无法查询没有isok字段的行(如果InfluxDB支持这种类型的查询,则可以像这个SELECT * FROM cost WHERE time NOT IN (SELECT isok FROM cost)那样进行查询)
发布于 2018-08-14 15:22:53
这并不完全是最初问题的答案,但我发现了一个特殊的技巧。
如果这个查询是由kapacitor执行的,它(kapacitor)有一个特殊的节点default,它允许添加一些值的缺失字段/标记。
对于health_ok查询,如下所示(tickscript):
var data = stream
|from()
.measurement('smart_device')
|default()
.field('health_ok', FALSE)这允许假设如果错过了health_ok,那么它就是FALSE。
https://stackoverflow.com/questions/51788320
复制相似问题