18

Is there a way to get Hive to output the results in a columnar-fashion, like the "\G" option available from MySQL?

http://dev.mysql.com/doc/refman//5.5/en/mysql-commands.html

Idr
  • 6,000
  • 6
  • 34
  • 49

2 Answers2

27

If you use HiveServer2 (Hive > 0.14), you can use "beeline" shell and there is "vertical" option.

0: jdbc:hive2://127.0.0.1:10000> !set outputformat table
0: jdbc:hive2://127.0.0.1:10000> select * from sample_07 limit 1;
+-----------------+------------------------+----------------------+-------------------+
| sample_07.code  | sample_07.description  | sample_07.total_emp  | sample_07.salary  |
+-----------------+------------------------+----------------------+-------------------+
| 00-0000         | All Occupations        | 134354250            | 40690             |
+-----------------+------------------------+----------------------+-------------------+
1 row selected (0.131 seconds)

0: jdbc:hive2://127.0.0.1:10000> !set outputformat vertical                          
0: jdbc:hive2://127.0.0.1:10000> select * from sample_07 limit 1;
sample_07.code         00-0000
sample_07.description  All Occupations
sample_07.total_emp    134354250
sample_07.salary       40690
1 row selected (0.063 seconds)

0: jdbc:hive2://127.0.0.1:10000> 
az3
  • 3,571
  • 31
  • 31
  • what is beeline shell . can you kindly tell how to invoke it . what command to use .? what are compatible hadoop versions? – Arun George May 15 '17 at 16:43
  • 1
    Worth noting that this is also possible on the command line: `beeline --outputformat=vertical -e "select * from blah"`. – abeboparebop May 01 '18 at 16:34
4

No there are no such facility in hive.

The result of map-reduce programs are always displayed row by row.

How ever, you can use Hive/Thrift server and write your hive queries though other scripting language like python and control the display of output. Only disadvantage is that you will have to parse the output and then display it.

pyfunc
  • 65,343
  • 15
  • 148
  • 136