描述表格

描述

DESCRIBE TABLE 语句返回表的基本元数据信息。元数据信息包括列名、列类型和列注释。可以选择性地指定一个分区规范或列名,以返回与分区或列相关的元数据。

语法

{ DESC | DESCRIBE } [ TABLE ] [ format ] table_identifier [ partition_spec ] [ col_name ]

参数

示例

-- 创建表 `customer`。假设当前数据库为 `salesdb`。
CREATE TABLE customer(
cust_id INT,
state VARCHAR(20),
name STRING COMMENT '短名称'
)
USING parquet
PARTITIONED BY (state);
INSERT INTO customer PARTITION (state = 'AR') VALUES (100, 'Mike');
-- 返回未限定表 `customer` 的基本元数据
DESCRIBE TABLE customer;
+-----------------------+---------+----------+
| col_name|data_type| comment|
+-----------------------+---------+----------+
| cust_id| int| null|
| name| string| 名称|
| state| string| null|
|# 分区 信息| | |
| # col_name|data_type| comment|
| state| string| null|
+-----------------------+---------+----------+
-- 返回限定表 `customer` 的基本元数据
DESCRIBE TABLE salesdb.customer;
+-----------------------+---------+----------+
| col_name|data_type| comment|
+-----------------------+---------+----------+
| cust_id| int| null|
| name| string| 名称|
| state| string| null|
|# 分区 信息| | |
| # col_name|data_type| comment|
| state| string| null|
+-----------------------+---------+----------+
-- 返回额外的元数据,如父数据库、所有者、访问时间等。
DESCRIBE TABLE EXTENDED customer;
+----------------------------+------------------------------+----------+
| col_name| data_type| comment|
+----------------------------+------------------------------+----------+
| cust_id| int| null|
| name| string| 名称|
| state| string| null|
| # 分区 信息| | |
| # col_name| data_type| comment|
| state| string| null|
| | | |
|# 详细  信息| | |
| 数据库| default| |
| | customer| |
| 所有者| <TABLE OWNER>| |
| 创建 时间| Tue Apr 07 22:56:34 JST 2020| |
| 最后 访问| 未知| |
| 创建 | <SPARK VERSION>| |
| 类型| 管理| |
| 提供者| parquet| |
| 位置|file:/tmp/salesdb.db/custom...| |
| Serde |org.apache.hadoop.hive.ql.i...| |
| InputFormat|org.apache.hadoop.hive.ql.i...| |
| OutputFormat|org.apache.hadoop.hive.ql.i...| |
| 分区 提供者| 目录| |
+----------------------------+------------------------------+----------+
-- 返回分区元数据,如分区列名称、列类型和注释。
DESCRIBE TABLE EXTENDED customer PARTITION (state = 'AR');
+------------------------------+------------------------------+----------+
| col_name| data_type| comment|
+------------------------------+------------------------------+----------+
| cust_id| int| null|
| name| string| 名称|
| state| string| null|
| # 分区 信息| | |
| # col_name| data_type| comment|
| state| string| null|
| | | |
|# 详细 分区 信息...| | |
| 数据库| default| |
| | customer| |
| 分区 | [state=AR]| |
| 位置|file:/tmp/salesdb.db/custom...| |
| Serde |org.apache.hadoop.hive.ql.i...| |
| InputFormat|org.apache.hadoop.hive.ql.i...| |
| OutputFormat|org.apache.hadoop.hive.ql.i...| |
+------------------------------+------------------------------+----------+
-- 返回 `name` 列的元数据。
-- 可选的 `TABLE` 子句已省略,列完全限定。
DESCRIBE customer salesdb.customer.name;
+---------+----------+
|info_name|info_value|
+---------+----------+
| col_name| name|
|data_type| string|
| comment| 名称|
+---------+----------+