hive shell查询时永久显示字段名或显示头(永久生效,不代表名,3种方案)

  • 介绍
    hive初步部署完成时,默认关闭了打印头的显示,在查询时不显示字段名,需要进行配置设置才会显示;
    配置以前,查询数据时,不显示字段名称,效果如下:
    在这里插入图片描述
	hive> select * from tmp_mult_partition limit 5;
	OK
1	a1	a2	b1	c1
2	a2	a2	b1	c1
3	a3	a2	b1	c1
4	a4	a2	b1	c1
5	a5	a2	b1	c1
  • 方案一、shell中临时显示
hive> -- 显示字段
    > set hive.cli.print.header=true;

设置成功,我们来看一下效果

在这里插入图片描述

hive> select * from tmp_mult_partition limit 5;
OK
tmp_mult_partition.id	tmp_mult_partition.title	tmp_mult_partition.a	tmp_mult_partition.b	tmp_mult_partition.c
1	a1	a2	b1	c1
2	a2	a2	b1	c1
3	a3	a2	b1	c1
4	a4	a2	b1	c1
5	a5	a2	b1	c1
Time taken: 0.243 seconds, Fetched: 5 row(s)

** 可以看到hive查询时已经显示字段名,打印头信息 ** 但带有表名,看起来不是很直观,表名主要是为了区别字段的唯一性,我们需要隐藏表名,可以通过设置hive.resultset.use.unique.column.names为false来实现

hive> -- 显示字段
    > set hive.cli.print.header=true;

hive>  select * from tmp_mult_partition limit 5;
OK
tmp_mult_partition.id	tmp_mult_partition.title	tmp_mult_partition.a	tmp_mult_partition.b	tmp_mult_partition.c
1	a1	a2	b1	c1
2	a2	a2	b1	c1
3	a3	a2	b1	c1
4	a4	a2	b1	c1
5	a5	a2	b1	c1
Time taken: 0.243 seconds, Fetched: 5 row(s)

hive> -- 只显示字段名
    > set  hive.resultset.use.unique.column.names=false;
hive> select * from tmp_mult_partition limit 5;
OK
id	title	a	b	c
1	a1	a2	b1	c1
2	a2	a2	b1	c1
3	a3	a2	b1	c1
4	a4	a2	b1	c1
5	a5	a2	b1	c1
Time taken: 0.283 seconds, Fetched: 5 row(s)

非常棒,达到我们的预期,仅显示字段名称
在这里插入图片描述

  • 方案二、所有集群客户端永久显示(cdh界面化配置)
    通过Cloudera Management 配置hive-site.xml,完成集群配置调整
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    查看是否配置更新成功:
    方式1.通过界面查看:

方式2.通过配置查看:

[hdfs@hbase-3 conf]$ cat hive-site.xml
...
  <property>
    <name>hive.cli.print.header</name>
    <value>true</value>
  </property>
  <property>
    <name>hive.resultset.use.unique.column.names</name>
    <value>false</value>
  </property>
</configuration>

效果验证:
在这里插入图片描述

hive> select * from tmp_mult_partition limit 5;
OK
id	title	a	b	c
1	a1	a2	b1	c1
2	a2	a2	b1	c1
3	a3	a2	b1	c1
4	a4	a2	b1	c1
5	a5	a2	b1	c1
Time taken: 0.283 seconds, Fetched: 5 row(s)
  • 方案三、所有集群客户端永久显示(配置文件调整)

修改 hive-site.xml文件

  <property>
    <name>hive.cli.print.header</name>
    <value>true</value>
  </property>
  <property>
    <name>hive.resultset.use.unique.column.names</name>
    <value>false</value>
  </property>

重启服务后
在这里插入图片描述

  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

时空琴弦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值