DESCRIBE TABLE

Description

DESCRIBE TABLE statement returns the basic metadata information of a table. The metadata information includes column name, column type and column comment. Optionally a partition spec or column name may be specified to return the metadata pertaining to a partition or column respectively.

Syntax

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

Parameters

  • format

    Specifies the optional format of describe output. If EXTENDED is specified then additional metadata information (such as parent database, owner, and access time) is returned.

  • table_identifier

    Specifies a table name, which may be optionally qualified with a database name.

    Syntax: [ database_name. ] table_name

  • partition_spec

    An optional parameter that specifies a comma separated list of key and value pairs for partitions. When specified, additional partition metadata is returned.

    Syntax: PARTITION ( partition_col_name = partition_col_val [ , ... ] )

  • col_name

    An optional parameter that specifies the column name that needs to be described. The supplied column name may be optionally qualified. Parameters partition_spec and col_name are mutually exclusive and can not be specified together. Currently nested columns are not allowed to be specified.

    Syntax: [ database_name. ] [ table_name. ] column_name

Examples

  1. -- Creates a table `customer`. Assumes current database is `salesdb`.
  2. CREATE TABLE customer(
  3. cust_id INT,
  4. state VARCHAR(20),
  5. name STRING COMMENT 'Short name'
  6. )
  7. USING parquet
  8. PARTITIONED BY (state);
  9. INSERT INTO customer PARTITION (state = 'AR') VALUES (100, 'Mike');
  10. -- Returns basic metadata information for unqualified table `customer`
  11. DESCRIBE TABLE customer;
  12. +-----------------------+---------+----------+
  13. | col_name|data_type| comment|
  14. +-----------------------+---------+----------+
  15. | cust_id| int| null|
  16. | name| string|Short name|
  17. | state| string| null|
  18. |# Partition Information| | |
  19. | # col_name|data_type| comment|
  20. | state| string| null|
  21. +-----------------------+---------+----------+
  22. -- Returns basic metadata information for qualified table `customer`
  23. DESCRIBE TABLE salesdb.customer;
  24. +-----------------------+---------+----------+
  25. | col_name|data_type| comment|
  26. +-----------------------+---------+----------+
  27. | cust_id| int| null|
  28. | name| string|Short name|
  29. | state| string| null|
  30. |# Partition Information| | |
  31. | # col_name|data_type| comment|
  32. | state| string| null|
  33. +-----------------------+---------+----------+
  34. -- Returns additional metadata such as parent database, owner, access time etc.
  35. DESCRIBE TABLE EXTENDED customer;
  36. +----------------------------+------------------------------+----------+
  37. | col_name| data_type| comment|
  38. +----------------------------+------------------------------+----------+
  39. | cust_id| int| null|
  40. | name| string|Short name|
  41. | state| string| null|
  42. | # Partition Information| | |
  43. | # col_name| data_type| comment|
  44. | state| string| null|
  45. | | | |
  46. |# Detailed Table Information| | |
  47. | Database| default| |
  48. | Table| customer| |
  49. | Owner| <TABLE OWNER>| |
  50. | Created Time| Tue Apr 07 22:56:34 JST 2020| |
  51. | Last Access| UNKNOWN| |
  52. | Created By| <SPARK VERSION>| |
  53. | Type| MANAGED| |
  54. | Provider| parquet| |
  55. | Location|file:/tmp/salesdb.db/custom...| |
  56. | Serde Library|org.apache.hadoop.hive.ql.i...| |
  57. | InputFormat|org.apache.hadoop.hive.ql.i...| |
  58. | OutputFormat|org.apache.hadoop.hive.ql.i...| |
  59. | Partition Provider| Catalog| |
  60. +----------------------------+------------------------------+----------+
  61. -- Returns partition metadata such as partitioning column name, column type and comment.
  62. DESCRIBE TABLE EXTENDED customer PARTITION (state = 'AR');
  63. +------------------------------+------------------------------+----------+
  64. | col_name| data_type| comment|
  65. +------------------------------+------------------------------+----------+
  66. | cust_id| int| null|
  67. | name| string|Short name|
  68. | state| string| null|
  69. | # Partition Information| | |
  70. | # col_name| data_type| comment|
  71. | state| string| null|
  72. | | | |
  73. |# Detailed Partition Inform...| | |
  74. | Database| default| |
  75. | Table| customer| |
  76. | Partition Values| [state=AR]| |
  77. | Location|file:/tmp/salesdb.db/custom...| |
  78. | Serde Library|org.apache.hadoop.hive.ql.i...| |
  79. | InputFormat|org.apache.hadoop.hive.ql.i...| |
  80. | OutputFormat|org.apache.hadoop.hive.ql.i...| |
  81. | Storage Properties|[serialization.format=1, pa...| |
  82. | Partition Parameters|{transient_lastDdlTime=1586...| |
  83. | Created Time| Tue Apr 07 23:05:43 JST 2020| |
  84. | Last Access| UNKNOWN| |
  85. | Partition Statistics| 659 bytes| |
  86. | | | |
  87. | # Storage Information| | |
  88. | Location|file:/tmp/salesdb.db/custom...| |
  89. | Serde Library|org.apache.hadoop.hive.ql.i...| |
  90. | InputFormat|org.apache.hadoop.hive.ql.i...| |
  91. | OutputFormat|org.apache.hadoop.hive.ql.i...| |
  92. +------------------------------+------------------------------+----------+
  93. -- Returns the metadata for `name` column.
  94. -- Optional `TABLE` clause is omitted and column is fully qualified.
  95. DESCRIBE customer salesdb.customer.name;
  96. +---------+----------+
  97. |info_name|info_value|
  98. +---------+----------+
  99. | col_name| name|
  100. |data_type| string|
  101. | comment|Short name|
  102. +---------+----------+