如何在Apache IoTDB中多条件查询时间序列?
问题
在Apache IoTDB 1.3.4中,root.db下存在多个数值型时间序列,例如:
`root.db.fac.mac.dev.value_pot` float `root.db.fac.mac.dev.value_tmp` double `root.db.fac.mac.dev.value_hdy` float `root.db.fac.mac.dev.value_len` int32 ...
需要查询所有名称包含value且数据类型为double的时间序列。
分别执行单条件查询可成功:
- SQL-1(查询名称含
value的序列):
show timeseries `root.db`.** where timeseries contains 'value'
返回结果:
+-----------------------------+-----+--------+--------+---------+-----------+----+----------+--------+------------------+--------+ | Timeseries|Alias|Database|DataType| Encoding|Compression|Tags|Attributes|Deadband|DeadbandParameters|ViewType| +-----------------------------+-----+--------+--------+---------+-----------+----+----------+--------+------------------+--------+ |`root.db.fac.mac.dev.value_pot`| `null`| `root.db`| FLOAT| GORILLA| LZ4|`null`| `null`| `null`| `null`| BASE| |`root.db.fac.mac.dev.value_tmp`| `null`| `root.db`| DOUBLE| GORILLA| LZ4|`null`| `null`| `null`| `null`| BASE| |`root.db.fac.mac.dev.value_hdy`| `null`| `root.db`| FLOAT| GORILLA| LZ4|`null`| `null`| `null`| `null`| BASE| |`root.db.fac.mac.dev.value_len`| `null`| `root.db`| INT32| TS_2DIFF| LZ4|`null`| `null`| `null`| `null`| BASE| +-----------------------------+-----+--------+--------+--------+-----------+----+----------+--------+------------------+--------+
- SQL-2(查询数据类型为
float的序列):
show timeseries `root.db`.** where datatype = float
返回结果:
+-----------------------------+-----+--------+--------+---------+-----------+----+----------+--------+------------------+--------+ | Timeseries|Alias|Database|DataType| Encoding|Compression|Tags|Attributes|Deadband|DeadbandParameters|ViewType| +-----------------------------+-----+--------+--------+---------+-----------+----+----------+--------+------------------+--------+ |`root.db.fac.mac.dev.value_pot`| `null`| `root.db`| FLOAT| GORILLA| LZ4|`null`| `null`| `null`| `null`| BASE| |`root.db.fac.mac.dev.value_hdy`| `null`| `root.db`| FLOAT| GORILLA| LZ4|`null`| `null`| `null`| `null`| BASE| |`root.db.fac.mac.dev.point_pot`| `null`| `root.db`| FLOAT| GORILLA| LZ4|`null`| `null`| `null`| `null`| BASE| +-----------------------------+-----+--------+--------+--------+-----------+----+----------+--------+------------------+--------+
但组合两个条件执行SQL-3时报错:
show timeseries `root.db`.** where timeseries contains 'value' and datatype = float
报错信息:
Msg: org.apache.iotdb.jdbc.IoTDBSQLException: 700: Error occurred while parsing SQL to physical plan: line 1:62 mismatched input 'and' expecting {, ';'}
询问IoTDB是否支持此类查询,以及如何调整SQL实现需求。
解决方案
Apache IoTDB 1.3.4版本的SHOW TIMESERIES语句不支持在WHERE子句中同时使用多个条件组合查询,这是该版本语法解析的限制。
要实现名称包含value且数据类型为double的序列查询,可通过以下两种方式解决:
方式1:升级版本后使用子查询
如果可以升级到IoTDB 1.4.0或更高版本,该版本支持子查询语法,可执行:
SELECT timeseries FROM (SHOW TIMESERIES `root.db`.** WHERE timeseries contains 'value') WHERE datatype = 'DOUBLE'
方式2:客户端侧过滤(适配1.3.4版本)
在1.3.4版本中,先执行单条件查询获取基础结果集,再在客户端代码或工具中做二次过滤:
- 先查询所有名称含
value的序列:
show timeseries `root.db`.** where timeseries contains 'value'
- 在客户端筛选结果中
DataType为DOUBLE的条目。
或者反过来,先查询所有DOUBLE类型的序列,再过滤名称含value的:
show timeseries `root.db`.** where datatype = double
之后在客户端筛选名称包含value的条目。
内容的提问来源于stack exchange,提问作者A Jing
相关产品推荐
相关产品推荐

