Hive: writing column headers to local file?

前端 未结 7 1488
别跟我提以往
别跟我提以往 2020-12-08 01:17

Hive documentation lacking again:

I\'d like to write the results of a query to a local file as well as the names of the columns.

Does Hive support this?

7条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-08 01:43

    Indeed, @nija's answer is correct - at least as far as I know. There isn't any way to write the column names when doing an insert overwrite into [local] directory ... (whether you use local or not).

    With regards to the crashes described by @user1735861, there is a known bug in hive 0.7.1 (fixed in 0.8.0) that, after doing set hive.cli.print.header=true;, causes a NullPointerException for any HQL command/query that produces no output. For example:

    $ hive -S
    hive> use default; 
    hive> set hive.cli.print.header=true;
    hive> use default;
    Exception in thread "main" java.lang.NullPointerException
        at org.apache.hadoop.hive.cli.CliDriver.processCmd(CliDriver.java:222)
        at org.apache.hadoop.hive.cli.CliDriver.processLine(CliDriver.java:287)
        at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:517)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:616)
        at org.apache.hadoop.util.RunJar.main(RunJar.java:197)
    

    Whereas this is fine:

    $ hive -S
    hive> set hive.cli.print.header=true;
    hive> select * from dual;
    c
    c
    hive> 
    

    Non-HQL commands are fine though (set,dfs !, etc...)

    More info here: https://issues.apache.org/jira/browse/HIVE-2334

提交回复
热议问题