hive元数据操作

南墨2年前技术文章683

1.查看hive从超过5000分区的表

select dbs.name, tbls.TBL_NAME, count(1) as part_count from dbs, tbls, partitions where dbs.DB_ID = tbls.DB_ID and tbls.TBL_ID = partitions.TBL_ID group by dbs.name, tbls.TBL_NAME having count(1) > 5000 order by part_count desc;

2.查看hive表信息

select dbs.name,tbls.tbl_name,tbls.tbl_type,sds.location,serdes.slib as serde,partition_keys.pkey_name from dbs,sds,serdes,tbls left join partition_keys on tbls.tbl_id=partition_keys.tbl_id where  dbs.db_id=tbls.db_id  and  tbls.sd_id=sds.sd_id  and  sds.serde_id=serdes.serde_id;

3.查看sds表数量级(此表数据量一般较大,会出现瓶颈,超过100w需注意)

select count(*) from sds;

4.查询某表的分区

SELECT p.* from PARTITIONS p
JOIN TBLS t
ON t.TBL_ID=p.TBL_ID
WHERE t.TBL_NAME='table'
AND PART_NAME like '%pt=xxxxx%';

5.查询指定库中stored as textfile类型的所有表名

select 
d.NAME,
t.TBL_NAME,
s.INPUT_FORMAT,
s.OUTPUT_FORMAT
from TBLS t
join DBS d
join SDS s
where t.DB_ID = d.DB_ID
and t.SD_ID = s.SD_ID
and d.NAME='test'
and s.INPUT_FORMAT like '%TextInputFormat%';

6.查询指定库中的分区表

select
db.NAME,
tb.TBL_NAME,
pk.PKEY_NAME
from TBLS tb
join DBS db
join PARTITION_KEYS pk
where tb.DB_ID = db.DB_ID
and tb.TBL_ID=pk.TBL_ID
and db.NAME='test';

7.查询指定库的非分区表

select
db.NAME,
tb.TBL_NAME
from TBLS tb
join DBS db
where tb.DB_ID = db.DB_ID
and db.NAME='test'
and tb.TBL_ID not in (
select distinct TBL_ID from PARTITION_KEYS
) ;

8.查看所有库信息

select db_id,name,owner_name from metastore.dbs;

9.查看指定库中所有表信息

select db_id,tbl_id,tbl_name,owner,tbl_type,create_time from metastore.tbls where db_id=51;

10.查看表的参数信息

select  * from table_params tp  where tbl_id=36;

11.查看指定表的所有字段信息

select cd_id,column_name,type_name,comment from metastore.columns_v2 where CD_ID=50;

12.查询使用某一个字段的表

SELECT t.table_name,c.column_name FROM information_schema.`TABLES` t

INNER JOIN information_schema.`COLUMNS` c

ON c.TABLE_NAME = t.TABLE_NAME

WHERE 

# 查询是否 都有 update_time 字段

c.COLUMN_NAME = 'update_time'

# 查询的数据库

AND t.TABLE_SCHEMA = 'data_exchange'

# 数据库中包含了其他的表, 使用模糊查询

AND t.TABLE_NAME LIKE '%dwd\_\ww\_0000%'


相关文章

MySQL运维实战之ProxySQL(9.9)proxysql自身高可用

MySQL运维实战之ProxySQL(9.9)proxysql自身高可用

proxysql作为一个程序,本身也可能出现故障。部署proxysql的服务器也肯能出现故障。高可用架构的一个基本原则是消除单点。可以在多个节点上部署proxysql,在proxysql之前再加一层负...

oracle PUS.SPU.CPU.BP.RU.RUR概念简介

PUS.SPU.CPU.BP.RU.RUR概念介绍PSU(Patch Set Updates):Oracle 选取在每个季度用户下载数量最多,并且得到验证具有较低风险的补丁放入到每个季度的PSU中,修...

PG的执行计划

一、Explain基本使用1.1 命令解释explain [ ( option [,...] ) ] statement explain [ analyze ] [ verbose ] statem...

linux下xfs文件系统类型/目录扩容

1、查看分区信息[root@172-16-121-112 ~]# fdisk -lDisk /dev/vda: 107.4 GB, 107374182400 bytes, 209715200 sect...

linux开启Firewall白名单限制ip访问

linux开启Firewall白名单限制ip访问

1、Firewalld是否启动成功systemctl start firewalld && systemctl enable firewalld 1 2、开启规则需求:客户由...

ES运维(四)扩容方式迁移

ES运维(四)扩容方式迁移

1 迁移概述本次模拟es在线迁移方式:集群扩容-->数据迁移-->老节点下线-->服务重启刷新配置。 中间master替换的时候会有短暂的不可用。 另外业务测需注意:老节点下线前...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。