质量监控Griffin

1 Griffin  概述

Apache Griffin 是一个开源的大数据数据质量解决方案,它支持批处理和流模式两种数
据质量检测方式,可以从不同维度度量数据资产,从而提升数据的准确度和可信度。例如:
离线任务执行完毕后检查源端和目标端的数据数量是否一致,源表的数据空值等。

2 Griffin  架构原理

UI创建Job

1)Measure 列表

2) Job 列表

 3) 监控仪表盘面板

 单击放大图片

ODS层数据校验

在 Hive 中创建表数据质量校验记录表,记录数据校验的各个指标

CREATE TABLE datacheck.table_count_add_standard (
    data_date string COMMENT '数据时间分区 dt',
    database_name string COMMENT '库名',
    table_name string COMMENT '表名',
    table_type string COMMENT '表类型(全量/增量)',
    add_count bigint COMMENT '当日增量数据的记录数',
    null_count bigint COMMENT '表空值记录数',
    total_count bigint COMMENT '全表记录数'
);

数据检验增量表通用 shell 脚本

#!/bin/bash

# 脚本参数注释:
# 第一个参数:传入时间分区参数( dt )
# 第二个参数:需要进行数据校验的表名( table_name )
# 第三个参数:需要判断是否为空值的字段名称用逗号‘ ,’隔开,例如:col1,col2,col3
# 脚本执行示例: 
# ./increment_data_check_public.sh 2020-03-10 ods_activity_rule id,activity_id

do_date=$1
table_name=$2
null_column=$3
null_where_sql_str=''
array=(${null_column//,/ })
for(( i=0;i<${#array[@]};i++)) do
if [ $i -eq 0 ];then
    null_where_sql_str=" where ${array[i]} is null "
else
    null_where_sql_str="$null_where_sql_str or ${array[i]} is null "
fi
done;
add_count_query_result=`hive -e "select count(*) from
gmall.$table_name where dt='$do_date'"`
add_count=${add_count_query_result:3}
echo ${add_count_query_result:3}

total_count_query_result=`hive -e "select count(*) from
gmall.$table_name"`
total_count=${total_count_query_result:3}

table_null_query_result=`hive -e "select count(*) from
gmall.$table_name $null_where_sql_str"`
null_count=${table_null_query_result:3}

hive -e "insert into datacheck.table_count_add_standard
values('$do_date','gmall','$table_name','increment_table',$add
_count,$null_count,'$total_count')"


数据检验全量表通用 shell 脚本

#!/bin/bash
do_date=$1
table_name=$2
null_column=$3
null_where_sql_str=''
array=(${null_column//,/ })
for(( i=0;i<${#array[@]};i++)) do
if [ $i -eq 0 ];then
    null_where_sql_str=" where ${array[i]} is null "
else
    null_where_sql_str="$null_where_sql_str or ${array[i]} is null "
fi
done;
table_count_query_result=`hive -e "select count(*) from gmall.$table_name"`
table_count=${table_count_query_result:3}

table_null_query_result=`hive -e "select count(*) from gmall.$table_name $null_where_sql_str"`
null_count=${table_null_query_result:3}

hive -e "insert into datacheck.table_count_add_standard
values('$do_date','gmall','$table_name','total_table',null,$null_count,'$table_count')

 ODS  层各表检验
1. 涉及表
增量检查
(1)订单详情表(ods_order_detail)
(2)用户表(ods_user_info)
(3)支付流水表(ods_payment_info)
(4)订单状态表(ods_order_status_log)
(5)商品评论表(ods_comment_info)
(6)退单表(ods_order_refund_info)
(7)活动订单关联表(ods_activity_order)
全量检查
(1)订单表( ods_order_info )
(2)SKU 商品表(ods_sku_info)
(3)商品一级分类表(ods_base_category1)
(4)商品二级分类表(ods_base_category2)
(5)商品三级分类表(ods_base_category3)
(6)品牌表(ods_base_trademark)
(7)SPU 商品表(ods_spu_info)
(8)加购表(ods_cart_info)
(9)商品收藏表(ods_favor_info)
(10)优惠券领用表(ods_coupon_use)
(11)优惠券表(ods_coupon_info)
(12)活动表(ods_activity_info)
(13)优惠规则表(ods_activity_rule)
(14)编码字典表(ods_base_dic)

 业务数据表
1 优惠券信息表
数据源表:ods_coupon_info
源表字段:id,coupon_name,coupon_type,condition_amount,condition_
num,activity_id,benefit_amount,benefit_discount,create_time,ra
nge_type,spu_id,tm_id,category3_id,limit_num,operate_time,expi
re_time
数据目标表: dwd_dim_coupon_info
目标表字段:id,coupon_name,coupon_type,condition_amount,condition
_num,activity_id,benefit_amount,benefit_discount,create_time,r
ange_type,spu_id,tm_id,category3_id,limit_num,operate_time,exp
ire_time
分区:dt='2020-03-10'
2 订单明细事实表
数据源表:ods_order_detail
源表字段:id,order_id,user_id,sku_id,sku_name,order_price,sku_nu
m,create_time
数据目标表:dwd_fact_order_detail
目标表字段:id,order_id,user_id,sku_id,sku_name,order_price,sku_n
um,create_time
分区:dt='2020-03-10'
3 支付事实表
数据源表:ods_payment_info
源表字段:id,out_trade_no,order_id,user_id,alipay_trade_no,total
_amount,subject,payment_type,payment_time
数据目标表:dwd_fact_payment_info
目标表字段:id,out_trade_no,order_id,user_id,alipay_trade_no,paym
ent_amount,subject,payment_type,payment_time
分区:dt='2020-03-10'
4 退款事实表
数据源表:ods_order_refund_info
源表字段:id,user_id,order_id,sku_id,refund_type,refund_num,refu
nd_amount,refund_reason_type,create_time

# 增量检查
# 订单详情表
/opt/module/data_check/sh/increment_data_check_public.sh
$data_date ods_order_detail
id,order_id,user_id,sku_id,sku_name,order_price,sku_num,create
_time
# 用户表
/opt/module/data_check/sh/increment_data_check_public.sh
$data_date ods_user_info
id,name,birthday,gender,email,user_level,create_time,operate_time
# 支付流水表
/opt/module/data_check/sh/increment_data_check_public.sh
$data_date ods_payment_info
id,out_trade_no,order_id,user_id,alipay_trade_no,total_amount,subject,payment_type,payment_time
# 订单状态表
/opt/module/data_check/sh/increment_data_check_public.sh
$data_date ods_order_status_log
id,order_id,order_status,operate_time
# 商品评论表
/opt/module/data_check/sh/increment_data_check_public.sh
$data_date ods_comment_info
id,user_id,sku_id,spu_id,order_id,appraise,create_time
# 退单表
/opt/module/data_check/sh/increment_data_check_public.sh
$data_date ods_order_refund_info
id,user_id,order_id,sku_id,refund_type,refund_num,refund_amount,refund_reason_type,create_tim

  使用 Griffin 

猜你喜欢

转载自blog.csdn.net/qq_22473611/article/details/118805793