Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get column name and type in hive

I know of these,

  • To get column names in a table we can fire:

    show columns in <database>.<table_name>
    
  • To get description of a table (including column_name, column_type and many other details):

    describe [formatted] <database>.<table_name>
    

I know that I can use the above query and filter the result to get the columns names and types. But I want to know if there is any direct command to get just the column names and types like select columns, column_type ...?

like image 494
Ani Menon Avatar asked Nov 12 '17 06:11

Ani Menon


People also ask

How do I get column names in Hive?

If you're executing any SELECT statement on Hive cli, only the rows are displayed. The column names are not displayed by default. To show the column headers, print. header property needs to be set to true.

Which command is used to display column names Hive?

use desc tablename from Hive CLI or beeline to get all the column names.

How do I SELECT columns in Hive?

The easiest way to select specific columns in the Hive query is by specifying the column name in the select statement. SELECT col1, col3, col4 .... FROM Table1; But imagine your table contains many columns (i.e : more than 100 columns) and you need to only exclude a few columns in the select statement.

How do you describe a column in Hive?

DESCRIBE shows/displays the list of columns (including partition columns) for the given table. EXTENDED, FORMATTED keyword is optional. If the EXTENDED is specified, it show/displays all the metadata for the specified table. If the FORMATTED is specified, it show/displays the metadata in a tabular format.


1 Answers

In HIVE you could use:

DESCRIBE FORMATTED [DatabaseName].[TableName] [Column Name];

This gives you the column data type and some stats of that column.

DESCRIBE [DatabaseName].[TableName] [Column Name];

This just gives you the data type and comments if available for a specific column.

Hope this helps.

like image 87
pramodM Avatar answered Sep 17 '22 12:09

pramodM