Tuesday 9 August 2022

Hive: Print columns names in SELECT statement output

When you execute a SELECT query on a table, it print all or matched records.

hive> SELECT * FROM emp;
OK
1   Hari    ["Football","Cricket"]  {"Java":"3.4Yrs","C":"4.5Yrs"}  {"gender":"Male","age":30}
2   Chamu   ["Trekking","Watching movies"]  {"Selenium":"5.6Yrs"}   {"gender":"Feale","age":38}
3   Sailu   ["Chess","Listening to music"]  {"EmbeddedC":"9Yrs"}    {"gender":"Femle","age":32}
4   Gopi    ["Cricket"] {"Datastage":"11Yrs"}   {"gender":"Male","age":32}
Time taken: 0.293 seconds, Fetched: 4 row(s)

 

As you see above snippet, Hive do not print the column names. Set the property ‘hive.cli.print.header’ to true in Hive CLI to print the column names.

 

SET hive.cli.print.header=true;

hive> SET hive.cli.print.header=true;
hive> SELECT * FROM emp;
OK
emp.id  emp.name    emp.hobbies emp.technology_experience   emp.gender_age
1   Hari    ["Football","Cricket"]  {"Java":"3.4Yrs","C":"4.5Yrs"}  {"gender":"Male","age":30}
2   Chamu   ["Trekking","Watching movies"]  {"Selenium":"5.6Yrs"}   {"gender":"Feale","age":38}
3   Sailu   ["Chess","Listening to music"]  {"EmbeddedC":"9Yrs"}    {"gender":"Femle","age":32}
4   Gopi    ["Cricket"] {"Datastage":"11Yrs"}   {"gender":"Male","age":32}
Time taken: 0.052 seconds, Fetched: 4 row(s)

 

 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment