简体   繁体   中英

Identifying Partitioned tables in Hive

Is there any way which allows listing of partitioned tables in Hive? I found the way which allows this to happen in SQL Server.

https://dba.stackexchange.com/questions/14996/how-do-i-get-a-list-of-all-the-partitioned-tables-in-my-database

I want to list only partitioned tables under a specific database so that I don't get to check the DDLs of numerous tables to find whether the table is partitioned or non-partitioned. Any similar functionality in Hive? Please suggest.

You can directly connect with the hive metastore data base and get the information about the tables which are partitioned. Need to know following information, may change according to your cluster configuration:

  1. The database(eg PostgreSQL,mysql etc) in which hive metastore is configured to store the metadata about the tables.
  2. Usually metastore is the database name in which table information are stored in hive metastore database.
  3. TBLS is the table which store hive table information. DBS is the table which store the hive database information and PARTITIONS is the table whoch store the information about partitioning in hive.
  4. DB_ID is the foreign key in TBLS and TBL_ID is the foreign key of TBLS in PARTITIONS .
  5. Join tables like below:

    select d."NAME" as DATABASE_NAME, t."TBL_NAME" as TABLE_NAME, p."PKEY_NAME" as PARTITION_KEY_NAME from "PARTITION" p join "TBLS" on p."TBL_ID"=t."TBL_ID" join "DBS" dat on t."DB_ID"=d."DB_ID" where d."NAME"="filterdbname" AND p."PKEY_NAME" is not null; This is the sql approach. If programmatic approach is needed. HiveMetaStoreClient APIs can be used to query the metastore tables. Metastore connection setup is needed. In java below is the pseudo code,

    import org.apache.hadoop.hive.conf.HiveConf; import org.apache.hadoop.hive.metastore.HiveMetaStoreClient;

    HiveConf conf = new HiveConf(); hiveConf.setVar(HiveConf.ConfVars.METASTOREURIS, Address+":"+ Port); HiveMetaStoreClient hiveMetaStoreClient = new HiveMetaStoreClient(conf);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM