首页 > 解决方案 > 对 hive 和 Metastore 的查询

问题描述

我想通过查询获取每列的列名和最小/最大值。

假设我只知道表的名称。

我知道以下查询。
表名=人

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

我可以将这两个查询合并为一个查询吗?

蜂巢中有没有像 information_schema 这样的表?

标签: hiveinformation-schemametastore

解决方案


可能重复:Hive,我如何检索所有数据库的表列

您可以使用以下命令列出表中的总列数:

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

下一步是遍历 table_list.txt 文件并构建一个包含所有字段名称及其最大/最小查询的查询字符串。

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

希望这可以帮助。


推荐阅读