Hive - How to display Hive query results in the Command Line along with column names

回眸只為那壹抹淺笑 提交于 2021-02-08 06:18:22

问题


I am working in Hive for quite a while . Please note that I don't use Hue at all. I use the Hive shell all the time and now I got a weird but useful question.

Whenever we execute a query in the Hive shell, we can see the relevant results on screen but we cannot recognise the column names corresponding to the data unless we do a "desc formatted table_name" or any other similar command and scroll up / down the screen to match the results with the table structure. We do this all the time most probably.

Just out of curiosity I want to know whether is there any way to print the column names along with the data atleast when we execute a basic query such as "select * from table_name" ?


回答1:


set this property once you open hive session

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

so that it will display your column names.

Example:

hive> desc sales;
OK
col_name        data_type       comment
year                    string
month                   string
customer                string
stateid                 string
productid               string
qty                     string
billed                  string

hive> select * from sales;
OK
2011    1.2     A       2       1       2       8
2011    5.2     C       3       1       1       8
2011    2       B       1       2       1       2
2011    3       B       1       2       2       2

once i set the above property

hive> set hive.cli.print.header=true;
hive> select * from sales;
OK
sales.year      sales.month     sales.customer  sales.stateid   sales.productid sales.qty       sales.billed
2011    1.2     A       2       1       2       8
2011    5.2     C       3       1       1       8
2011    2       B       1       2       1       2

if you want to get rid of table name i.e sales. before each column name then set the below property

hive> set hive.resultset.use.unique.column.names=false;
hive> select * from sales;
OK
year    month   customer        stateid productid       qty     billed
2011    1.2     A       2       1       2       8
2011    5.2     C       3       1       1       8
2011    2       B       1       2       1       2

(or)

As a permanent solution,you can find and change this property value to true in your hive-site.xml.



来源:https://stackoverflow.com/questions/48896362/hive-how-to-display-hive-query-results-in-the-command-line-along-with-column-n

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!