Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Just get column names from hive table

Tags:

sql

hadoop

hive

I know that you can get column names from a table via the following trick in hive:

hive> set hive.cli.print.header=true; hive> select * from tablename; 

Is it also possible to just get the column names from the table?

I dislike having to change a setting for something I only need once.

My current solution is the following:

hive> set hive.cli.print.header=true; hive> select * from tablename; hive> set hive.cli.print.header=false; 

This seems too verbose and against the DRY-principle.

like image 566
cantdutchthis Avatar asked Oct 03 '14 14:10

cantdutchthis


People also ask

How do I SELECT only column names in Hive?

use desc tablename from Hive CLI or beeline to get all the column names. If you want the column names in a file then run the below command from the shell. where dbname is the name of the Hive database where your table is residing You can find the file columnnames. txt in your root directory.

How do I get a list of column names in a table?

sp_columns procedure To get the column name of a table we use sp_help with the name of the object or table name. sp_columns returns all the column names of the object. The following query will return the table's column names: sp_columns @table_name = 'News'

How do I get column names and data types in Hive?

In HIVE you could use: DESCRIBE FORMATTED [DatabaseName]. [TableName] [Column Name]; This gives you the column data type and some stats of that column.


1 Answers

If you simply want to see the column names this one line should provide it without changing any settings:

describe database.tablename; 

However, if that doesn't work for your version of hive this code will provide it, but your default database will now be the database you are using:

use database; describe tablename; 
like image 104
JJFord3 Avatar answered Sep 24 '22 15:09

JJFord3