hive元数据操作

南墨2年前技术文章726

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%'


相关文章

Ubuntu 网卡启动及配置

Ubuntu 网卡启动及配置

问题分析打开虚拟机后发现没有网卡网络。查看网卡信息sudo ip link set ens33 up1得到本机的所有网卡信息,例如我这边网卡为ens33启动网卡启动网卡后发现依然网卡没有IP地址。配置...

python-序列化和反序列化

1、为什么要序列化内存中的字典、列表、集合以及各种对象,如何保存到一个文件中?如果是自己定义的类的实例,如何保存到一个文件中?如何从文件中读取数据,并让它们在内存中再次恢复成自己对应的类的实例?要设计...

apache Kyuubi部署及对接hive

apache Kyuubi部署及对接hive

1、背景客户重度使用spark sql,但是使用spark thriftserver存在各种各样的问题,我们选择使用kyuubi来替代spark thriftserver的使用2、安装包下载下载地址:...

通过Nodeport方式暴露集群

通过Nodeport方式暴露集群

一、原理图二、通过deployment部署双副本nginx,两个Pod[root@172-16-121-211 ~]# cat nginx-delpayment01.yml apiVersion: a...

PG的锁(一)

一、表级锁1.1 表级锁模式常见锁模式以及应用场景:ACCESS SHARE :select操作获取该模式锁资源,通常情况下所有只读取不修改表的查询都会获取该模式锁资源ROW SHARE : sele...

Phoenix SQLLine快速使用

Phoenix SQLLine快速使用

1、启动在Phoenix主目录下bin文件夹中,执行以下命令:bin/sqlline.py master其中master为Zookeeper中的节点,如果有多个节点,中间使用逗号分开。执行该命令后,客...

发表评论    

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