Is there a way to get the column name along with the output when executing any query in Hive?

In Hive, when we execute a query (for example: select * from employee ), we do not get any column names in the output (for example, name, age, salary that we get in SQL DBMS ), we get only values.

Is there a way for column names to be displayed along with the output when executing any query?

+49
rdbms hadoop hive
Aug 01 '13 at 5:27
source share
7 answers

If we want to see table column names in HiveQl, the following conf property for hive must be set to true.

 hive> set hive.cli.print.header=true; 

If you prefer to see column names, always update the $ HOME / .hiverc file with the above setting on the first line.

- Hive automatically searches for a file named .hiverc in your HOME directory and runs the commands it contains, if any

+103
Aug 01 '13 at 12:06 on
source share

To print the header along with the output, the following conf property for hive must be set before executing the request.

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

We can also use such a query if we want to get the result in a file.

 hive -e 'set hive.cli.print.header=true;select * from table_name;' > result.xls 

Where table_name is the name of your table

+10
Aug 01
source share

All the above answers already answer the question. But in case someone wants this property to be constantly enabled, then this property: hive.cli.print.header in hive-default.xml or hive-site.xml .

The default value is false. Make its meaning true and save. Done.

+5
Jun 16 '15 at 19:51
source share

Set this property before executing the query:

 hive> set hive.cli.print.header=true; 
+1
Aug 01 '13 at 7:16
source share

Most solutions are accurate.

setting the hive.cli.print.header = true property works.

But if you use cloudera, HDP or any other distributions, this will reset. Therefore, update this value in your Hive configurations and restart the services.

This will be a permanent fix. hope this helps.

+1
Sep 07 '15 at 20:07
source share

Use set hive.cli.print.header=true;

 hive> set hive.cli.print.header=true; hive> select * from tblemployee; OK id name gender salary departmentid 1 tomr male 40000 1 2 cats female 30000 2 3 john male 50000 1 4 james male 35000 3 5 sara female 29000 2 6 bens male 35000 1 7 saman female 30000 NULL 8 russel male 40000 2 9 valar female 30000 1 10 todd male 95000 NULL Time taken: 9.892 seconds 
0
Jul 09 '15 at 17:54
source share
 1)Permenant solution change this property in hive-site.xml file under $HIVE_HOME/conf folder <property> <name>hive.cli.print.header</name> <value>true</value> <description>Whether to print the names of the columns in query output. </description> </property> 2)Temporary solution: go to hive prompt execute this comman hive>set hive.cli.print.header=True 
0
Jul 10 '17 at 11:37
source share



All Articles