hive元数据操作

南墨2年前技术文章667

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


相关文章

PG体系结构(三)

PG体系结构(三)

四、物理结构4.1 软件安装目录bin             //二进制可执行文件 include         //头文件目录 lib             //动态库文件 share ...

kubernetes openelb

1、背景在云服务环境中的 Kubernetes 集群里,通常可以用云服务提供商提供的负载均衡服务来暴露 Service,但是在本地没办法这样操作。而 OpenELB 可以让用户在裸金属服务器、边缘以及...

K8s cni0网卡异常

K8s cni0网卡异常

一、问题现象pod启动时,调度到其中某个节点上的pod都无法正常启动,查看启动报错:network: failed to set bridge addr: "cni0" alrea...

Shell中单引号和双引号区别

1)在/home/atguigu/bin创建一个test.sh文件[atguigu@hadoop102 bin]$ vim test.sh在文件中添加如下内容#!/bin/bashdo_date=$1...

8.0 新特性-Redo 配置的变化

8.0 新特性-Redo 配置的变化

说明本篇文章将介绍 MySQL Redo 日志的作用,及需要关注的参数,在 5.7、8.0 Redo 的变化。1. Redo 日志介绍1.1. Redo 有什么作用为了取得更好的读写性能,InnoDB...

发表评论    

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