通过hive元数据查询hive指定库和表的总条数

一、整库下,总条数

1、指定库的表总数

查看ods层的总表数

select count(TBL_NAME)  
from TBLS t   
left join DBS d  
on t.DB_ID = d.DB_ID  
where d.NAME like 'ods_%'  and t.TBL_NAME like "ods_%";

2、非分区表的总条数

查看ods库的总条数

select FORMAT(sum(tb.PARAM_VALUE),0)  
from TBLS t   
left join DBS d  
on t.DB_ID = d.DB_ID  
left join TABLE_PARAMS tb 
on t.TBL_ID = tb.TBL_ID   
where d.NAME like 'ods_%' and tb.PARAM_KEY='numRows' and t.TBL_NAME like "ods_%";  

3、查询含有分区表的总条数

查看ods库的总条数

select FORMAT(sum(a.PARAM_VALUE),0)  
from TBLS t   
left join DBS d  
on t.DB_ID = d.DB_ID  
left join PARTITIONS p  
on t.TBL_ID = p.TBL_ID   
left join PARTITION_PARAMS a  
on p.PART_ID=a.PART_ID  
where d.NAME like 'ods_%' and a.PARAM_KEY='numRows' and t.TBL_NAME like "ods_%"  

4、查询某天含有分区表的总条数

查看ods库的总条数

select FORMAT(sum(a.PARAM_VALUE),0)  
from TBLS t   
left join DBS d  
on t.DB_ID = d.DB_ID  
left join PARTITIONS p  
on t.TBL_ID = p.TBL_ID   
left join PARTITION_PARAMS a  
on p.PART_ID=a.PART_ID  
where d.NAME like 'ods_%' and a.PARAM_KEY='numRows' and t.TBL_NAME like "ods_%"  
and  date(from_unixtime(p.create_time)) =  '2023-01-20' ; 
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值