数据质量之评估维度及检测项
数据质量直接影响数据的价值,这里主要介绍一些业界主流的六大评估维度,分别是完整性,唯一性(独特性),一致性,准确性,有效性,时效性。以及我们在设计DQC的时候可以用什么检查规则取检测。
一、完整性
数据的每一项都应被记录,这样数据才完整。
我们可以通过对字段是否为空或者是否为空字符串进行检测数据的完整性
-- 空值检测
select count(1) as cnt from ${db}.${table} where (${filter}) and (${field} is null)
-- 空字符串检测
select count(1) as cnt from ${db}.${table} where (${filter}) and (trim(${field}) = '' )
-- 空值或空字符串检测
select count(1) from ${db}.${table} where (${filter}) and (${field} is null or trim(${field}) = '' )
二、唯一性
也成为独特性,即数据是否存在重复,每条数据是否是唯一的
可以通过对主键或者自定义复合字段检测是否重复
-- 重复检查
select count(1) as cnt
from(
select ${field_concat},count(1) cnt from ${db}.${table} where ${filter} group by ${field_concat} having count(1)>1
)tmp
三、一致性
一致性即数据在迁移或者加工前后是否一致,可以通过源表数据量与目标表的数据量检测,也可以通过具体字段匹配检测
-- 表行数检测
select count(1) as cnt from ${db}.${table} where ${filter}
四、准确性
准确性是指该数据是否能反映业务的内容,可以对数据的某些字段的总和检测、平均值检测、最大最小值检测是否与业务状况相似
-- 总和检测
select sum(${field}) as mysum from ${db}.${table} where ${filter}
-- 平均值检测
select avg(${field}) as myavg from ${db}.${table} where ${filter}
-- 最大值检测
select max(${field}) as mymax from ${db}.${table} where ${filter}
-- 最小值检测
select min(${field}) as mymin from ${db}.${table} where ${filter}
五、有效性
有效性是指该数据是否符合规则,如日期字段的数据是否符合统一的日期格式,金额的字段数值范围是否合理,身份证字段数据是否合规等等
-- 日期格式检测
select count(1) as cnt from ${db}.${table} where (${filter}) and (${field} not regexp '${regexp}')
-- 数据格式检测
select count(1) as cnt from ${db}.${table} where (${filter}) and (${field} not regexp '${regexp}')
-- 数值范围检测
select count(1) as cnt from ${db}.${table} where (${filter}) and (not (${filter2}))
-- 身份证检测
select count(1) as cnt from ${db}.${table} where (${filter}) and (${field} not regexp '${regexp}')
-- 枚举值检测
select count(1) as cnt from ${db}.${table} where (${filter}) and (${field} not in ( ${list} ) or ${field} is null)
-- 正则表达式检测
select count(1) as cnt from ${db}.${table} where (${filter}) and (${field} not regexp '${regexp}')
六、时效性
数据是有时效性的,是指该数据是反映那个时间段的,在数仓中,可以对数据的更新频率,和时间差做检测,或者设置关键任务的超时告警来监控.