hiveinformation-schemametastore

query to both hive and metastore


I want to get column names and min/max of each columns with query.

Assume that i only know the name of table.

i know below queries.
table_name=people

select min(some_col_name_which_don't_know) from people
SELECT t.TBL_ID, d.NAME as `schema`, t.TBL_NAME name, t.TBL_TYPE, tp.PARAM_VALUE as description,
           p.PKEY_NAME as col_name, p.INTEGER_IDX as col_sort_order,
           p.PKEY_TYPE as col_type, p.PKEY_COMMENT as col_description, 1 as "is_partition_col",
           IF(t.TBL_TYPE = 'VIRTUAL_VIEW', 1, 0) "is_view"
FROM TBLS t
JOIN DBS d ON t.DB_ID = d.DB_ID
JOIN PARTITION_KEYS p ON t.TBL_ID = p.TBL_ID
WHRER TBL_NAME=people

Can i merge these two queries to one query?

All is there any table like information_schema in hive?


Solution

  • Possible Duplicate: Hive, how do I retrieve all the database's tables columns

    You could list the total number of columns in a table using the below command:

    hive -e "show columns in <table name>" > table_list.txt

    Next step would be to iterate over the table_list.txt file and build a query string with all the field names and its max/min queries.

     for column in table_list:
       hive -e "select min("+column+") from <table name>" >> min_max_table.txt
    

    Hope this helps.