在Hive中,当我们执行查询(例如:
有没有办法在执行任何查询时显示列名?
select * from employee
)时,不会在输出结果中得到任何列名(例如在RDBMS SQL中获取的名称、年龄、工资),我们只能得到值。有没有办法在执行任何查询时显示列名?
hive> set hive.cli.print.header=true;
如果您希望始终查看列名称,请在$HOME/.hiverc文件的第一行中更新以上设置。要在输出中打印标题,必须在执行查询之前将以下Hive配置属性设置为true。
hive> set hive.cli.print.header=true;
hive> select * from table_name;
如果我们想要在文件中获取结果,我们也可以像这样使用查询。
hive -e 'set hive.cli.print.header=true;select * from table_name;' > result.xls
请填入您的表名称 table_name
hive-default.xml
或hive-site.xml
中使用此属性:hive.cli.print.header
。1)Permenant solution
change this property in hive-site.xml file under $HIVE_HOME/conf folder
<property>
<name>hive.cli.print.header</name>
<value>true</value>
<description>Whether to print the names of the columns in query output.
</description>
</property>
2)Temporary solution:
go to hive prompt execute this comman
hive>set hive.cli.print.header=True
hive.cli.print.header = true
设置为真即可。hive> set hive.cli.print.header=true;
使用 set hive.cli.print.header=true;
hive> set hive.cli.print.header=true;
hive> select * from tblemployee;
OK
id name gender salary departmentid
1 tomr male 40000 1
2 cats female 30000 2
3 john male 50000 1
4 james male 35000 3
5 sara female 29000 2
6 bens male 35000 1
7 saman female 30000 NULL
8 russel male 40000 2
9 valar female 30000 1
10 todd male 95000 NULL
Time taken: 9.892 seconds