databasesequence-alignmentapache-iotdb

How to query latest value of large amount of devices that are all aligned in Apache IoTDB?


IoTDB> select last * from root.station01.cell.bms01.bunch01.** limit 10 align by device;  
Msg: 701: Last query doesn't support align by device.

I tried this statement in Apache IoTDB: select last * from root.station01.cell.bms01.bunch01.** limit 10 align by device, and got this error: Msg: 701: Last query doesn't support align by device. Seems like query align by device do not support querying the latest data value for each device? If so, how do I query the latest value of each device if I have hundreds of device nodes? My device time series are all aligned and all collected at one time.


Solution

  • There are two ways to achieve your goal in Apache IoTDB:

    1. select max_time(any time series under the device), last_value(*) from root.station01.cell.bms01.bunch01.** limit 10 align by device;
    2. select last * from root.station01.cell.bms01.bunch01.** limit 10;

    The second method returns the time series overview. You can add order by timeseries, then the timeseries in the same device will be returned together, then the upper layer will do the processing.