Search code examples
time-seriesapache-iotdb

How does apache IOTDB query the time of the last change of data?


In IoTDB, there are time series under root.device_id, where xxxx represents multiple series. I would like to query for the last changed value and the time of change under root.device_id. How should I write the query statement? such as :1,2,2,3,3,3,3,3,3,i need find when data change from 2 to 3


Solution

  • In Apache IoTDB, you can use diff or change_points function to implement your requirement.

    Here is the example sqls:

    CREATE TIMESERIES root.db.d1.s1 INT32;
    INSERT INTO root.db.d1(timestamp,s1) values(1,1),(2,2),(3,2),(4,3),(5,3),(6,3),(7,3),(8,3),(9,3);
    select s1 from root.db.d1 where diff(s1) != 0 limit 2;
    select max_time(s1), last_value(s1) from root.db.d1 where diff(s1) != 0;
    select change_points(s1) from root.db.d1;
    select change_points(s1) from root.db.d1 order by time desc limit 2;
    

    Here is the running results: running results

    change_points