Hive-如何在命令行中显示Hive查询结果以及列名 [英] Hive - How to display Hive query results in the Command Line along with column names

查看:73
本文介绍了Hive-如何在命令行中显示Hive查询结果以及列名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Hive工作了一段时间.请注意,我根本不使用Hue.我一直都在使用Hive外壳,现在我遇到了一个奇怪但有用的问题.

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.

无论何时我们在Hive shell中执行查询,我们都可以在屏幕上看到相关结果,但是除非执行"desc格式的table_name"或任何其他类似的命令并向上滚动/,否则我们无法识别与数据相对应的列名.在屏幕上向下移动以使结果与表结构匹配.我们很可能一直在这样做.

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.

出于好奇,我想知道在执行诸如"select * from table_name"之类的基本查询时,是否有任何方法可以至少打印列名和数据?

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" ?

推荐答案

在打开配置单元会话后设置此属性

set this property once you open hive session

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

,以便显示您的列名.

示例:

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

设置完以上属性

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

(或)

作为永久解决方案,您可以在 hive-site.xml 中找到并将此属性值更改为 true .

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

这篇关于Hive-如何在命令行中显示Hive查询结果以及列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆