Check if a hive table is partitioned on a given column

大城市里の小女人 提交于 2021-02-17 04:42:12

问题


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.


回答1:


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

The exact syntax of querying your metastore depends on your particular choice of metastore (in my case is a PostgreSQL one).



来源:https://stackoverflow.com/questions/44945446/check-if-a-hive-table-is-partitioned-on-a-given-column

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!