Influxdb 如何从缺少字段的流入数据库中进行查询?
我用电传收集了一份测量数据。其结构如下: 名称:智能手机Influxdb 如何从缺少字段的流入数据库中进行查询?,influxdb,kapacitor,Influxdb,Kapacitor,我用电传收集了一份测量数据。其结构如下: 名称:智能手机 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
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
但是,当我尝试筛选出健康状况为空的记录时,我会得到空输出:
> select * from smart_device where "health_ok"!= true
>
如何选择带有空no的测量值?无效的健康状况良好?不幸的是,目前无法使用InfluxQL实现这一点。XDB是一种面向文档的数据库形式;这意味着度量的行可以有不同的模式。因此,行的字段不存在null的概念;实际上这一行没有字段。例如,假设度量成本中有4行 如您所见,有两行isok=true,两行没有名为isok的字段;因此,只有一种方法可以通过此查询选择具有isok字段的行的时间:
> select isok from cost
name: cost
time isok
---- ----
1533970927859614000 true
1533970938243629700 true
由于InfluxQL目前不支持where子句中的子查询,因此如果InfluxDB支持这种类型的查询,则无法查询没有isok字段的行,您可以像这样从成本中选择*,而时间不在从成本中选择isok这不完全是原始问题的答案,但我为卡帕西托找到了一个特别的窍门 如果此查询是由kapacitor执行的,则kapacitor有一个特殊的节点默认值,该默认值允许添加缺少的字段/标记以及一些值 对于health_ok查询,它将如下所示:
var data = stream
|from()
.measurement('smart_device')
|default()
.field('health_ok', FALSE)
这允许假设,如果健康状况未得到确认,则为假
var data = stream
|from()
.measurement('smart_device')
|default()
.field('health_ok', FALSE)