在Hive中,当我们执行查询时(例如:),我们  select * from employee不会在输出中获得任何列名称(例如在RDBMS SQL中获得的名称,年龄,薪水),我们只会获得值。
当执行任何查询时,有什么方法可以使列名与输出一起显示?
在Hive中,当我们执行查询时(例如:),我们  select * from employee不会在输出中获得任何列名称(例如在RDBMS SQL中获得的名称,年龄,薪水),我们只会获得值。
当执行任何查询时,有什么方法可以使列名与输出一起显示?
Answers:
如果我们想在HiveQl中查看表的列名,则以下hive conf属性应设置为true。
hive> set hive.cli.print.header=true;
如果您希望始终查看列名,请在第一行中使用上述设置更新$ HOME / .hiverc文件。
--Hive自动在您的HOME目录中查找名为.hiverc的文件,并运行其中包含的命令(如果有)
若要将标头与输出一起输出,应在执行查询之前将以下hive conf属性设置为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您的表名
采用 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
    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