Is there any way to get the column name along with the output while execute any query in Hive?
Solution 1:
If we want to see the columns names of the table in HiveQl, the following hive conf property should be set to true.
hive> set hive.cli.print.header=true;
If you prefer to see the column names always then update the $HOME/.hiverc file with the above setting in the first line..
--Hive automatically looks for a file named .hiverc in your HOME directory and runs the commands it contains, if any
Solution 2:
To print header along with the output, the following hive conf property should be set to true before executing the query.
hive> set hive.cli.print.header=true;
hive> select * from table_name;
We can also use query like this, if we want to get result in file.
hive -e 'set hive.cli.print.header=true;select * from table_name;' > result.xls
Where table_name your table name