规则类型 | 标识 | 说明 |
系统模板 | system_template | 使用系统内置的检测模板,只需指定 template_code 即可。系统模板已内置质量维度,用户无需指定 dimension。 |
自定义 SQL | custom_sql | 用户编写自定义 SQL 查询语句,灵活实现各种检测逻辑。需要用户指定 dimension(质量维度)和 custom_sql(SQL 语句)。 |
规则级别 | 配置节点 | 说明 |
表级规则 | table_rules | 针对整张表进行检测,如行数检查、数据产出及时性检查等。 |
字段级规则 | field_rules | 针对表中的某个具体字段进行检测,如空值率、重复值、平均值等。需额外指定 field_name。 |
维度标识 | 中文名 | 说明 |
completeness | 完整性 | 检测数据是否存在缺失 |
accuracy | 准确性 | 检测数据值是否在合理范围内 |
validity | 有效性 | 检测数据格式、类型是否合规 |
uniqueness | 唯一性 | 检测数据是否存在重复 |
consistency | 一致性 | 检测不同数据源或表之间数据是否一致 |
timeliness | 及时性 | 检测数据是否按时产出 |
模板标识 | 名称 | 说明 | trigger_condition |
table_row_count | 表行数 | 检测表的总行数是否在合理范围内 | 用户自定义 |
data_timeliness | 数据产出及时性 | 检测数据是否按时产出 | 系统固定无需填写。通过 filter 配置业务过滤条件 |
模板标识 | 名称 | 说明 | trigger_condition |
null_count | 字段空值个数 | 统计字段中空值的个数 | 用户自定义 |
null_rate | 字段空值率 | 统计字段中空值占比 | 用户自定义 |
not_null_count | 字段非空计数 | 统计字段中非空值的个数 | 用户自定义 |
duplicate_count | 字段重复值个数 | 统计字段中存在重复的值的个数 | 用户自定义 |
distinct_count | 字段去重计数 | 统计字段中不同值的个数 | 用户自定义 |
min_value | 字段最小值 | 获取字段的最小值 | 用户自定义 |
max_value | 字段最大值 | 获取字段的最大值 | 用户自定义 |
sum_value | 字段求和 | 计算字段的总和 | 用户自定义 |
avg_value | 字段平均值 | 计算字段的平均值 | 用户自定义 |
median_value | 字段中位数 | 计算字段的中位数 | 用户自定义 |
std_dev | 字段标准差 | 计算字段的标准差 | 用户自定义 |
enum_range_consistency | 枚举范围一致性 | 检测字段值是否在合法枚举范围内 | 系统固定无需填写。通过 params.enum_values 配置合法枚举值列表 |
运算符 | 含义 |
== | 等于 |
!= | 不等于 |
> | 大于 | |
< | 小于 |
= | 大于等于 | |
<= | 小于等于 |
trigger_condition: "> 100" # 检测值大于 100 则触发trigger_condition: "<= 0" # 检测值小于等于 0 则触发trigger_condition: "== 24" # 检测值等于 24 则触发trigger_condition: "!= 0" # 检测值不等于 0 则触发trigger_condition: "> 0" # 检测值大于 0 则触发
括号 | 含义 |
[ 或 ] | 包含边界值(闭区间) |
( 或 ) | 不包含边界值(开区间) |
表达式 | 含义 | 触发时机 |
between [0,150] | 值落在 0到150 内 | 值在区间内时触发 |
between (0,100) | 值落在 0到100 内 | 值在区间内时触发(不含边界) |
between [0,100) | 值落在 0到100 内 | 值在区间内时触发(含左不含右) |
between (0,100] | 值落在 0到100 内 | 值在区间内时触发(不含左含右) |
not_between [0,100] | 值不在 0到100 内 | 值超出区间时触发 |
not_between (0,100) | 值不在 0到100 内 | 值超出区间时触发 |
trigger_condition: "not_between [1000,1000000]"# 表行数不在此范围内则触发trigger_condition: "not_between [10, 10000]"# 字段均值不在此范围内则触发trigger_condition: "not_between [1, 50]"# 去重计数不在此范围内则触发
连接词 | 含义 |
AND | 所有条件同时满足时触发 |
OR | 任一条件满足时触发 |
trigger_condition: "< 100 OR > 1000000" # 行数过少或过多均触发trigger_condition: "> 100 AND < 200" # 值大于100且小于200时触发
trigger_condition: "check_value > 0"# SQL返回列名为check_valuetrigger_condition: "null_count == 0"# SQL返回列名为null_counttrigger_condition: "check_value > 0 AND total_count >= 100"# 多列组合判断trigger_condition: "check_value not_between [0, 100]"# 区间也支持
模板或类型 | trigger_condition 配置方式 | 补充说明 |
普通系统模板(如 table_row_count、null_rate、avg_value 等) | 用户自定义。支持简单比较、区间、组合条件 | 无 |
data_timeliness 模板 | 无需填写,触发条件由系统固定 | 通过 filter 字段配置业务过滤逻辑 |
enum_range_consistency 模板 | 无需填写,触发条件由系统固定 | 通过 params.enum_values 配置合法枚举值列表 |
自定义 SQL | 用户自定义。支持带字段名前缀的所有表达式格式 | trigger_condition 中的字段名须与 SQL 返回的列名一致 |
字段 | 类型 | 必填 | 说明 |
rule_name | string | 是 | 规则名称,建议使用描述性名称 |
rule_type | string | 是 | 规则类型:system_template 或 custom_sql |
trigger_condition | string | 视模板而定 | 触发条件表达式(部分模板由系统固定,无需填写) |
filter | string | 否 | 可选,附加 WHERE 过滤条件 |
字段 | 类型 | 必填 | 说明 |
template_code | string | 是 | 系统模板标识,通过 DescribeRuleTemplates 接口查询 |
params | object | 否 | 部分模板需要的额外参数 |
字段 | 类型 | 必填 | 说明 |
custom_sql | string | 是 | 自定义 SQL 查询语句 |
dimension | string | 是 | 质量维度:completeness、accuracy、validity、uniqueness、consistency、timeliness |
字段 | 类型 | 必填 | 说明 |
field_name | string | 是 | 目标检测字段名称 |
table_rules:- rule_name: 表行数范围检查rule_type: system_templatetemplate_code: table_row_counttrigger_condition: not_between [1000,1000000]filter: status != DELETED
table_rules:- rule_name: 表行数异常检查rule_type: system_templatetemplate_code: table_row_counttrigger_condition: < 100 OR > 1000000
table_rules:- rule_name: 数据产出及时性检查rule_type: system_templatetemplate_code: data_timelinessfilter: update_time >= DATE_SUB(NOW(), INTERVAL 2 HOUR)
table_rules:- rule_name: 订单金额一致性检查rule_type: custom_sqldimension: consistencycustom_sql: >SELECT ABS((SELECT SUM(order_amount) FROM order_table WHERE dt = 20260101)- (SELECT SUM(detail_amount) FROM order_detail_table WHERE dt = 20260101)) as check_value FROM dualtrigger_condition: check_value != 0
field_rules:- field_name: user_idrule_name: 用户ID空值率检查rule_type: system_templatetemplate_code: null_ratetrigger_condition: "> 0"
field_rules:- field_name: order_idrule_name: 订单ID重复值检查rule_type: system_templatetemplate_code: duplicate_counttrigger_condition: "> 0"
field_rules:- field_name: order_amountrule_name: 订单金额均值检查rule_type: system_templatetemplate_code: avg_valuetrigger_condition: not_between [10, 10000]
field_rules:- field_name: phone_numberrule_name: 手机号格式校验rule_type: custom_sqldimension: validitycustom_sql:SELECT COUNT(*) as check_valueFROM user_info_table WHERE dt = 20260101AND phone_number IS NOT NULLAND phone_number NOT REGEXP 1[3-9][0-9]{9}trigger_condition: check_value > 0
field_rules:- field_name: genderrule_name: 性别枚举值范围一致性校验rule_type: system_templatetemplate_code: enum_range_consistencyparams:enum_values: M,F,Unknown
场景 | 推荐类型 |
标准的字段统计检查(空值率、重复值、均值等) | system_template |
跨表数据一致性比对 | custom_sql |
复杂业务逻辑校验(格式、范围、关联检查等) | custom_sql |
简单的表行数或及时性检查 | system_template |
文档反馈