自定义指标规则

如果系统提供的指标类型无法满足需求,您可以使用自定义指标规则。

定义自定义指标规则

assertion中使用一个自定义的指标名称,同时在规则配置中,添加这个自定义指标名称的配置,在配置值中给出自定义指标的SQL查询语句。示例如下:

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;"

保留问题数据

可以为自定义指标规则添加保留问题数据的设置,除了开启collectFailedRows外,还需要添加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"