How to Pretty Print Hive Output

15,354

Solution 1

Use

set hive.cli.print.header=true;

to print column names [1].

As for the spacing, the output is already tab separated so how you process it further is up to you.

[1] https://cwiki.apache.org/confluence/display/Hive/Configuration+Properties#ConfigurationProperties-CommandLineInterface

Solution 2

You can now also use the Beeline command line tool which outputs data in a pretty format. [0]

Should you want vertical output, like MySQL \G, you can set --outputformat=vertical.

[0] https://cwiki.apache.org/confluence/display/Hive/HiveServer2+Clients#HiveServer2Clients-Beeline%E2%80%93NewCommandLineShell

Share:
15,354

Related videos on Youtube

David Williams
Author by

David Williams

Updated on September 14, 2022

Comments

  • David Williams
    David Williams over 1 year

    How do I have Hive print out nicely formatted results, with column names and pleasantly space, such as mysql? For example:

    $ hive -f performanceStatistics.hql
    ...
    Kill Command = /usr/lib/hadoop/bin/hadoop job  -kill job_201306211023_1053
    Hadoop job information for Stage-1: number of mappers: 8; number of reducers: 1
    2013-09-04 17:30:56,092 Stage-1 map = 0%,  reduce = 0%
    2013-09-04 17:31:03,132 Stage-1 map = 25%,  reduce = 0%, Cumulative CPU 13.87 sec
    ...
    MapReduce Total cumulative CPU time: 2 minutes 5 seconds 260 msec
    Ended Job = job_201306211023_1053
    MapReduce Jobs Launched:
    Job 0: Map: 8  Reduce: 1   Cumulative CPU: 125.26 sec   HDFS Read: 1568029694 HDFS Write: 93 SUCCESS
    Total MapReduce CPU Time Spent: 2 minutes 5 seconds 260 msec
    OK
    19.866045211878546  0.023310810810810812    10  0   824821  25  1684.478659112734   0.16516737901191694
    Time taken: 34.324 seconds
    

    How do I get the results with the column names and good spacing? I would also like to have an extended view like mysql \G or \x in PostgreSQL.