All Products
Search
Document Center

DataWorks:Create and manage custom rule templates

Last Updated:Mar 26, 2026

When you manage data quality at scale, writing the same rule logic repeatedly for each table is error-prone and hard to maintain. Rule templates let you define custom SQL monitoring logic once and reuse it across as many tables as you need. When you update a template, only the rules that actively reference it are affected—monitoring rules created from earlier versions remain unchanged.

Prerequisites

Before you begin, ensure that you have:

  • DataWorks Enterprise Edition or a higher edition activated

Why use rule templates

RecommendationBenefit
Define SQL logic once in a templateApply the same monitoring rule to multiple tables without rewriting SQL each time
Organize templates in foldersGroup related templates by domain or team for easier discovery and reuse
Update templates centrallyChange a template's logic in one place; only rules that reference the changed template are affected

Create a rule template

  1. Log on to the DataWorks console. In the top navigation bar, select the target region. In the left-side navigation pane, choose Data Governance > Data Quality, select a workspace from the drop-down list, and click Go to Data Quality.

  2. In the left-side navigation pane, choose Assets > Rule Template Library.

  3. Click the 新建 icon and select Create Folder.

  4. In the Create Folder dialog box, set the Name and Location parameters and click OK.

  5. In the directory tree, right-click the folder and select Create Rule Template.

    Note: You can also rename or delete the folder from the right-click menu.
  6. In the Create Rule Template dialog box, configure the parameters.

    image.png

    ParameterDescription
    Template NameThe name of the rule template.
    FieldThe fields to monitor. Fixed to Custom SQL.
    Sampling MethodThe sampling method. Fixed to Custom SQL.
    Set FlagThe SET clause of the SQL statement used to query the monitored fields. Separate multiple statements with commas (,). Do not add a semicolon (;) at the end of each statement.
    Check typeThe threshold type. Valid values: Numeric type and Fluctuation.
    Verification MethodThe comparison method for the check result. Options depend on the Check type value—see the table below.
    Custom SQLThe SQL statement that queries the fields to monitor. Use ${tableName} as a placeholder for the table name. The query must return a single value that can be compared against a threshold.
    LocationThe folder in which to store the template.

    Verification methods and required thresholds by check type

    The Verification Method options and the thresholds you must define when applying the template both depend on the Check type you select.

    Check typeVerification method optionsThresholds required when applying
    Numeric typeCompare with a specified value — the query must return a single COUNT or SUM value, which is compared against a fixed numberNormal threshold + critical threshold
    FluctuationCompare the current value with the average value of the last 7 daysNormal threshold + warning threshold + critical threshold
    FluctuationCompare the current value with the average value of the last 30 daysNormal threshold + warning threshold + critical threshold
    FluctuationCompare the current value with the value 1 day beforeNormal threshold + warning threshold + critical threshold
    FluctuationCompare the current value with the value 7 days beforeNormal threshold + warning threshold + critical threshold
    FluctuationCompare the current value with the value 30 days beforeNormal threshold + warning threshold + critical threshold
    FluctuationThe variance between the current value and the value 7 days beforeNormal threshold + warning threshold + critical threshold
    FluctuationThe variance between the current value and the value 30 days beforeNormal threshold + warning threshold + critical threshold
    FluctuationCompare with the value 1, 7, and 30 days beforeNormal threshold + warning threshold + critical threshold
    FluctuationCompare with the value of the previous cycleNormal threshold + warning threshold + critical threshold

    Custom SQL and the `${tableName}` placeholder

    Use ${tableName} in your SQL to make the template reusable across tables. DataWorks substitutes the actual table name at runtime. The query must return a single value in a single row. For Numeric type checks, that value must be the output of COUNT or SUM.

  7. Click OK.

Manage a rule template

Click the name of a template in the Rule Template Library to open its details page. From there you can view, edit, delete, or copy the template.

ActionSteps
ViewReview the template's parameter settings, the rules that reference it (Application List tab), and its operation history (View Log tab). The View Log tab records the user, timestamp, and details of each operation.
EditClick Edit in the upper-right corner, update the parameters in the Edit Rule Template dialog box, and click OK.
DeleteClick Delete in the upper-right corner and confirm in the Delete Template message.
CopyClick Copy in the upper-right corner. In the Clone Rule Template dialog box, set a new Template Name and Location, then click OK.
Note: Changes to a custom rule take effect only for tasks that reference the changed custom rule. Existing tasks for which the original custom rule is applied are not affected.

Apply a rule template to a monitoring rule

  1. From the Data Quality page, choose Configure Rules > Configure by Table in the left-side navigation pane.

  2. In the Connection section, select the database where the table for which you want to configure rules resides. Find the target table by filtering on database type, database, and table name. Click the table name or click Rule Management in the Actions column to open the Table Quality Details page. The page lists all rules configured for the table. For rules not associated with a monitor, you can set the running mode directly from this page.

    image

  3. On the Rule Management tab, select a monitor and click Create Rule. The Create Rule panel opens.

  4. Select your custom rule template. The FLAG parameter and SQL fields are populated automatically from the template. Set the Rule Name and configure thresholds based on the template's check type:

    Check typeThresholds to configure
    Numeric typeNormal threshold and critical threshold
    FluctuationNormal threshold, warning threshold, and critical threshold

    image

  5. Click Determine.

What's next