一、目的
在数据质量模块,需要对原始数据的准确性进行统计
二、Hive中原有代码
2.1 表结构
--42、数据准确性统计表 dwd_data_accuracy create table if not exists hurys_db.dwd_data_accuracy( data_type int comment '1:转向比,2:统计,3:评价,4:区域,5:过车,6:静态排队,7:动态排队,8:轨迹,9:事件数据,10:事件资源', device_no string comment '设备编号', field_name string comment '字段名', data_unreasonable_rate float comment '数据不合理率', data_null_rate float comment '数据空值率' ) comment '数据准确性统计表' partitioned by (day string) stored as orc ;
2.2 SQL代码
insert overwrite table hurys_db.dwd_data_accuracy partition(day) select t1.data_type, t1.device_no, t1.field_name, round((sum(case when t1.field_value is not null then 1 else 0 end)/t2.count_device_all),2) data_unreasonable_rate, round((sum(case when t1.field_value is null then 1 else 0 end)