问题
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