Contact Us
Log In

Rule Engine

Last Updated on : 2021-07-08 12:48:34download

This topic describes how to manage the rule engine in the Data Analytics Platform.

Manage a rule engine

  1. Log in to the Data Analytics Platform.

  2. In the left navigation bar, click Data > Data Analysis > Rule Engine, and the rule engine management is displayed. All your created rule engines are displayed on this page. For more information about each item, see the following table. Rule Engine

    Item Description
    Rule name User-defined rule name, within 128 bytes. Click the rule name and find the rule details.
    Type The type of the created rule, including Edit Code and Low-Code Edit. Only Edit Code is available currently.
    Created on The time when a rule is created.
    Modified on The last time when a rule is updated.
    Data source The raw data source processed by the rule engine.
    Status Four types of status are available currently.
    • To be executed: A rule has not been started since it is created.
    • Executing: After you click Start, the status changes to Executing.
    • Stopped: For a rule in Executing, after you click Stopped, the status changes to Stopped.
    • Failed: If an executing rule is stopped due to an exception, the status changes to Failed.
    • Edit: Click it to edit a rule.
    • Delete: Click it to delete a rule, which is not available for an Executing rule.
    • Start/Stopped: Click it to start or stop a rule.

Create a rule by code editing


You have added at least a data source.


  1. In the left navigation bar, click Data > Data Analysis > Rule Engine.

  2. Click New Rule. Since the low-code edit is not available currently, editing code is displayed by default. Rule Engine

  3. Configure the script.

    1. Enter the rule name and select the data source and data type. The datapoint report has defaulted. The table name and table structure are displayed.
    2. Edit the Flink SQL statement in the right edit box according to the table structure. Tuya provides common templates. You can import a template and edit it accordingly. Rule Engine


    • The select field in the Flink SQL edit box must be renamed with as.
    • The update and insert operations are not supported currently.
    • For the public beta version, only summary data can be used, and detailed data cannot be saved. The keyword of group by must be included in the SQL.
  4. Configure data transfer. Only the real-time table is supported currently. Kafka and MQTT messages for billing users is coming soon.

    • Data storage table name: You can define it.
    • Data storage period: How long the data is retained. Only 7-day, 14-day, and 30-day are available currently.
    • Table field definition: The table field is parsed according to the above-mentioned Flink SQL. You can reset the field type and description and select whether to create an index. Rule Engine

    Note: Creating an index will speed up pagination but consume additional storage. Select it as needed.

  5. Test the rule engine.

    1. Click Test at the bottom of the page.
    2. The rule engine will be executed, including message subscription of data source, real-time processing, and writing data to a data table. Rule creation can be completed when all the tests are passed. If the test fails, you close the window and modify the code. After modification, repeat the above procedure to test. Rule Engine