查询配置单元元数据

cngwdvgl  于 2021-05-29  发布在  Hadoop
关注(0)|答案(1)|浏览(446)

我需要查询下表并查看来自apache hive群集的信息:
每行需要包含以下内容:
表架构
表名
表说明
列名
列数据类型
列长度
列精度
柱式比例尺
空或不空
主键指示器
这可以很容易地从大多数rdbms(元数据表/视图)中查询到,但是我很难找到关于hive中等效元数据表/视图的更多信息。
请帮忙:)

lyr7nygr

lyr7nygr1#

此信息可从配置单元元存储库获得。下面的示例查询是针对mysql支持的元存储(HiveVersion1.2)。

SELECT 
DBS.NAME AS TABLE_SCHEMA,
TBLS.TBL_NAME AS TABLE_NAME,
TBL_COMMENTS.TBL_COMMENT AS TABLE_DESCRIPTION,
COLUMNS_V2.COLUMN_NAME AS COLUMN_NAME,
COLUMNS_V2.TYPE_NAME AS COLUMN_DATA_TYPE_DETAILS
FROM DBS
JOIN TBLS ON DBS.DB_ID = TBLS.DB_ID
JOIN SDS ON TBLS.SD_ID = SDS.SD_ID
JOIN COLUMNS_V2 ON COLUMNS_V2.CD_ID = SDS.CD_ID
JOIN 
    (
        SELECT DISTINCT TBL_ID, TBL_COMMENT 
        FROM 
        (
            SELECT TBLS.TBL_ID TBL_ID, TABLE_PARAMS.PARAM_KEY, TABLE_PARAMS.PARAM_VALUE, CASE WHEN TABLE_PARAMS.PARAM_KEY = 'comment' THEN TABLE_PARAMS.PARAM_VALUE ELSE '' END TBL_COMMENT
            FROM TBLS JOIN TABLE_PARAMS
            ON TBLS.TBL_ID = TABLE_PARAMS.TBL_ID
        ) TBL_COMMENTS_INTERNAL
    ) TBL_COMMENTS 
ON TBLS.TBL_ID = TBL_COMMENTS.TBL_ID;

样本输出:

+--------------+----------------------+-----------------------+-------------------+------------------------------+
| TABLE_SCHEMA | TABLE_NAME           | TABLE_DESCRIPTION     | COLUMN_NAME       | COLUMN_DATA_TYPE_DETAILS     |
+--------------+----------------------+-----------------------+-------------------+------------------------------+
| default      | temp003              | This is temp003 table | col1              | string                       |
| default      | temp003              | This is temp003 table | col2              | array<string>                |
| default      | temp003              | This is temp003 table | col3              | array<string>                |
| default      | temp003              | This is temp003 table | col4              | int                          |
| default      | temp003              | This is temp003 table | col5              | decimal(10,2)                |
| default      | temp004              |                       | col11             | string                       |
| default      | temp004              |                       | col21             | array<string>                |
| default      | temp004              |                       | col31             | array<string>                |
| default      | temp004              |                       | col41             | int                          |
| default      | temp004              |                       | col51             | decimal(10,2)                |
+--------------+----------------------+-----------------------+-------------------+------------------------------+

查询中引用的元存储表:

DBS: Details of databases/schemas.
TBLS: Details of tables.
COLUMNS_V2: Details about columns.
SDS: Details about storage.
TABLE_PARAMS: Details about table parameters (key-value pairs)

相关问题