MaxCompute元数据分析冷热门表,充分优化数据模型

1、需求场景分析
在实际的数据平台运营管理过程当中,数据表的规模每每随着更多业务数据的接入以及数据应用的建设而逐渐增加到很是大的规模,数据管理人员每每但愿可以利用元数据的分析来更好地掌握不一样数据表的使用状况,从而优化数据模型。
一个MaxCompute项目中常常使用的表简称为热门表,使用次数较少或者很长时间不使用的表简称为冷门表,本文将介绍如何去经过MaxCompute元数据信息去分析热门表和冷门表。
2、方案设计思路
MaxCompute Information_Schema提供了项目中全量的表元数据信息Tables以及包含访问表的做业明细数据tasks_history,经过汇总各个表被做业访问的次数能够获知不一样表被做业使用的频度。
详细步骤以下:
一、热门数据经过获取tasks_history表里的input_tables字段的详细信息,而后经过count统计必定时间分区内的各个表使用次数
二、冷门数据经过tables和tasks_history里的input_tables表的做业汇总数量进行关联、排序,从而统计出各张表在规定时间内的使用次数,正序排列
3、方案实现方法
一、获取tasks_history表里的input_tables字段的详细信息。以下图所示:
select 
inst_id ,
input_tables,
output_tables,
start_time,
end_time 
from information_schema.tasks_history 
where ds='20190902'limit 100;函数

查询数据的结果以下图所示:
1
发如今tasks_history表中input_tables字段格式为
["lightning.customer","lightning.orders_delta"]
因此在统计的时候须要对字段进行按逗号分割
注意:案例中的时间分区能够根据需求去调整范围,区间根据实际场景去作相应的调整
例如:Ds>='20190902' and Ds<='20190905'
函数处理以下:
select
--去掉input_tables 字段中开始和结尾的[]
trans_array(1,",",inst_id,replace(replace(input_tables,"[",""),"]","")) as (inst_id,input_table)
from information_schema.tasks_history
--日期能够根据实际需求去限定,这里以20190902为例
where ds='20190902' limit 100;优化

处理结果以下图:
1spa

二、统计热门表数据SQL编写:
select 
--按表名进行统计计算
input_table
,count(distinct inst_id) table_read_num 
from 
(
select 
--去掉input_tables 字段中开始和结尾的[]
trans_array(1,",",inst_id,replace(replace(input_tables,"[",""),"]","")) as (inst_id,input_table) 
from information_schema.tasks_history 
where ds='20190902' 
) t
group by input_table
order by table_read_num desc
limit 1000;设计

结果以下图所示:
1regexp

三、统计冷门表数据SQL编写:
经过tables和tasks_history里的input_tables表的做业汇总数量进行关联、排序,从而统计出各张表在规定时间内的使用次数,正序排列。
select
t1.table_schema,
t1.table_name,
--两表关联
if(t2.table_read_num is null,0,table_read_num) as table_read_num
FROM information_schema.tables t1 
left join(
select
--去掉表名先后的”符号
regexp_replace(t.input_table,""","") as input_table
,count(distinct t.inst_id) table_read_num
from
(
select
--去掉input_tables 字段中开始和结尾的[]
trans_array(1,",",inst_id,replace(replace(input_tables,"[",""),"]","")) as (inst_id,input_table)
from information_schema.tasks_history 
where ds='20190902' )t
group by input_table
)t2
--关联条件匹配
on concat('your_project_name.',t1.table_name)=t2.input_table
order by table_read_num desc
limit 1000;orm

结果以下所示:
1
1
全部的表按照使用次数进行排序
便可获得各个表的使用次数排序信息。从而去进行合理化的管理数据表。
注意:SQL中的” your_project_name.”为表名前缀,客户须要参照本身的实际数据去作相应的修改调整。blog

 

 

查看更多:https://yqh.aliyun.com/detail/6669排序

上云就看云栖号:更多云资讯,上云案例,最佳实践,产品入门,访问:https://yqh.aliyun.com/input

相关文章
相关标签/搜索