检查配置单元表是否在给定列上分区 [英] Check if a hive table is partitioned on a given column
问题描述
我有一个配置单元表的列表,其中一些已分区.给定一列,我需要检查特定的表是否在该列上进行了分区.我搜索后发现, desc格式的表名将导致表的所有详细信息.由于我必须遍历所有表并获取列表,因此将desc格式化将无济于事.还有其他方法可以做到吗?
I have a list of hive tables , of which some are partitioned. Given a column I need to check if a particular table is partitioned on that column or not. I have searched and found that desc formatted tablename would result in all the details of the table. Since I have to iterate over all the tables and get the list , desc formatted would not help. Is there any other way this can be done.
推荐答案
您可以直接连接到元存储并对其进行查询:
You can connect directly to metastore and query it:
metastore=# select d."NAME" as DATABASE,
t."TBL_NAME" as TABLE,
p."PKEY_NAME" as PARTITION_KEY
from "PARTITION_KEYS" p
join "TBLS" t on p."TBL_ID"=t."TBL_ID"
join "DBS" d on t."DB_ID"=d."DB_ID";
database | table | partition_key
----------+-------------+---------------
default | src_union_1 | ds
default | cbo_t1 | dt
default | cbo_t2 | dt
查询元存储的确切语法取决于您对元存储的特定选择(在我的情况下是PostgreSQL).
The exact syntax of querying your metastore depends on your particular choice of metastore (in my case is a PostgreSQL one).
这篇关于检查配置单元表是否在给定列上分区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!