All Products
Search
Document Center

DataWorks:Custom metric rules

Last Updated:Dec 10, 2025

You can use custom metric rules if the built-in metric types do not meet your needs.

Define a custom metric rule

To define a custom metric rule, specify a custom metric name in the assertion. In the rule configuration, add a configuration for that metric name and provide its SQL query in the value. For example:

datasets:
  - type: Table
    tables:
      - tb_d_spec_demo
    filter: "dt='$[yyyymmdd]' AND hh='$[hh24-1/24]'"
    dataSource:
      name: odps_first
      envType: Dev

rules:
  - assertion: "avg_order_span between 5 and 10"
    avg_order_span:
      query: "SELECT COUNT(safety_stock_level - days_to_manufacture) FROM dim_product;"

Retain problem data

You can configure custom metric rules to retain problem data. In addition to enabling collectFailedRows, you must also add failedRowsQuery.

datasets:
  - type: Table
    tables:
      - tb_d_spec_demo
    filter: "dt='$[yyyymmdd]' AND hh='$[hh24-1/24]'"
    dataSource:
      name: odps_first
      envType: Dev

rules:
  - assertion: "id_for_belgium between 5 and 10"
    id_for_belgium:
      query: "SELECT count(*) FROM product_b;"
    collectFailedRows: true
    failedRowsQuery: "SELECT id FROM product_b WHERE id IS NULL"