Hadoop 在配置单元中执行任何查询时,是否有方法获取列名和输出?
在配置单元中,当我们执行查询(如:Hadoop 在配置单元中执行任何查询时,是否有方法获取列名和输出?,hadoop,hive,rdbms,Hadoop,Hive,Rdbms,在配置单元中,当我们执行查询(如:select*from employee)时,我们不会在输出中获得任何列名(如姓名、年龄、薪水,我们将在RDBMS SQL中获得),我们只会获得值 执行任何查询时,是否有任何方法可以使列名与输出一起显示?在执行查询之前设置此属性: hive> set hive.cli.print.header=true; 要将标题与输出一起打印,在执行查询之前,应将以下配置单元配置文件属性设置为true hive> set hive.cli.print.heade
select*from employee
)时,我们不会在输出中获得任何列名(如姓名、年龄、薪水,我们将在RDBMS SQL中获得),我们只会获得值
执行任何查询时,是否有任何方法可以使列名与输出一起显示?在执行查询之前设置此属性:
hive> set hive.cli.print.header=true;
要将标题与输出一起打印,在执行查询之前,应将以下配置单元配置文件属性设置为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您的表名如果希望在HiveQl中查看表的列名,则应将以下hive conf属性设置为true
hive> set hive.cli.print.header=true;
如果希望始终查看列名,请在第一行中使用上述设置更新$HOME/.hiverc文件
--Hive会自动在主目录中查找名为.hiverc的文件,并运行其中包含的命令(如果有)以上所有答案都已回答了问题。但如果有人想永久启用此属性,则在
hive default.xml
或hive site.xml
中有此属性:hive.cli.print.header
其默认值为false。使其值为真并保存。
完成。使用
设置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
大多数解决方案都是准确的
设置属性hive.cli.print.header=true
有效
但是,如果您使用的是cloudera、HDP或任何其他发行版,这些将被重置。因此,在配置单元配置中更新这些值并重新启动服务
这将是一个永久的解决办法。希望这有帮助。1)永久解决方案
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_HOME/conf文件夹下的hive-site.xml文件中更改此属性
hive.cli.print.header
真的
是否打印查询输出中列的名称。
2) 临时解决办法:
转到配置单元提示符执行此命令
配置单元>设置配置单元.cli.print.header=True
如果.hiverc文件不存在,您也可以创建一个文件并添加上述行。echo“SET hive.cli.print.header=true;”>~/.hivercy如果配置了安装,您还可以在hive-site.xml中将属性“hive.cli.print.header”设置为true。