描述表格
描述
DESCRIBE TABLE
语句返回表的基本元数据信息。元数据信息包括列名、列类型和列注释。可以选择性地指定一个分区规范或列名,以返回与分区或列相关的元数据。
语法
{ DESC | DESCRIBE } [ TABLE ] [ format ] table_identifier [ partition_spec ] [ col_name ]
参数
-
format
指定描述输出的可选格式。如果指定了
EXTENDED,将返回额外的元数据(例如父数据库、所有者和访问时间)。 -
table_identifier
指定表名称,可以选择性地附加数据库名称。
Syntax:
[ database_name. ] table_name -
partition_spec
一个可选参数,指定一个以逗号分隔的键值对列表,用于分区。当指定时,将返回额外的分区元数据。
Syntax:
PARTITION ( partition_col_name = partition_col_val [ , ... ] ) -
col_name
一个可选参数,指定需要描述的列名。提供的列名可以选择性地附加。参数
partition_spec和col_name互斥,不能同时指定。目前不允许指定嵌套列。Syntax:
[ database_name. ] [ table_name. ] column_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|短 名称|
+---------+----------+