Stream Processing

    With the stream processing engine built into TDengine, you can process incoming data streams in real time and define stream transformations in SQL. Incoming data is automatically processed, and the results are pushed to specified tables based on triggering rules that you define. This is a lightweight alternative to complex processing engines that returns computation results in milliseconds even in high throughput scenarios.

    The stream processing engine includes data filtering, scalar function computation (including user-defined functions), and window aggregation, with support for sliding windows, session windows, and event windows. Stream processing can write data to supertables from other supertables, standard tables, or subtables. When you create a stream, the target supertable is automatically created. New data is then processed and written to that supertable according to the rules defined for the stream. You can use PARTITION BY statements to partition the data by table name or tag. Separate partitions are then written to different subtables within the target supertable.

    For more information, see Stream Processing.

    For more information, see Stream Processing.

    A database including one supertable and four subtables is created as follows:

    1. CREATE DATABASE power;
    2. USE power;
    3. CREATE STABLE meters (ts timestamp, current float, voltage int, phase float) TAGS (location binary(64), groupId int);
    4. CREATE TABLE d1002 USING meters TAGS ("California.SanFrancisco", 3);
    5. CREATE TABLE d1004 USING meters TAGS ("California.LosAngeles", 3);

    Create a Stream

    1. insert into d1001 values("2018-10-03 14:38:05.000", 10.30000, 219, 0.31000);
    2. insert into d1001 values("2018-10-03 14:38:15.000", 12.60000, 218, 0.33000);
    3. insert into d1002 values("2018-10-03 14:38:16.650", 10.30000, 218, 0.25000);
    4. insert into d1003 values("2018-10-03 14:38:05.500", 11.80000, 221, 0.28000);
    5. insert into d1003 values("2018-10-03 14:38:16.600", 13.40000, 223, 0.29000);
    6. insert into d1004 values("2018-10-03 14:38:05.000", 10.80000, 223, 0.29000);
    7. insert into d1004 values("2018-10-03 14:38:06.500", 11.50000, 221, 0.35000);

    Query the Results

    In this scenario, the active power and reactive power are determined from the data gathered in the previous scenario. The location and name of each meter are concatenated with a period (.) between them, and the data set is partitioned by meter name and written to a new database.

    Create a Stream

      The procedure from the previous scenario is used to write the data.

      Query the Results