赞
踩
有时我们需要获取特定 HIVE 库下所有分区表,或者所有分区表的所有分区,以便执行进一步的操作,比如通过 使用 HIVE 命令 MSCK REPAIR TABLE table_name sync partitions 修复 HIVE 元数据与 HDFS 数据在分区上的不一致性。
怎么获取这些 hms 元数据呢?
获取 HMS 元数据,大体有以下几种方案:
相关的 hive sql 命令有:
show databases;
show tables;
show tables like table_name_regexp;
show create table xxx;
DESCRIBE DATABASE EXTENDED db_name;
DESCRIBE EXTENDED|FORMATTED db_name.table_name;
DESCRIBE EXTENDED|FORMATTED db_name.table_name PARTITION partition_spec;
hdfs dfs -ls -R hdfs:///user/hundsun/dap/hive | egrep part_date=[0-9]{8}$ |awk -F '/' 'BEGIN { OFS="." ;}{print $8,$9}' | uniq
# 获取指定HIVE库下所有分区表-访问 hms 数据库并执行sql:
select distinct d.NAME,t.TBL_NAME
from tbls t join dbs d join partitions p
on t.DB_ID=d.DB_ID and t.TBL_ID=p.TBL_ID
where d.name in ("hs_sr","hs_ods","hs_mid");
# 获取指定HIVE库下所有分区表的所有分区-访问 hms 数据库并执行sql:
select d.NAME,t.TBL_NAME,p.PART_NAME
from tbls t join dbs d join partitions p
on t.DB_ID=d.DB_ID and t.TBL_ID=p.TBL_ID
where d.name in ("hs_sr","hs_ods","hs_mid");
- table "dbs" stores the information of hive databases;
- table "TBLS" stores the information of Hive tables;
- table "PARTITIONS" stores the information of Hive table partitions;
- table "SDS" stores the information of storage location, input and output formats, SERDE etc;
- table hive.dbs has below important columns:DB_ID,NAME,DB_LOCATION_URI;
- tablet hive.bls has below important column:TBL_ID,DB_ID,SD_ID,TBL_NAME;
- table hive.partitions has below important column:PART_ID,PART_NAME,SD_ID,TBL_ID;
- table hive.sds has below important column:SD_ID,LOCATION;
- Both table "TBLS" and "PARTITIONS" have a foreign key referencing to SDS(SD_ID);
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。