Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hive query results in vertical format like MySQL's "\G"?

Tags:

hive

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

like image 656
Idr Avatar asked Jun 24 '12 18:06

Idr


People also ask

How do you store the results of hive query in a variable in a shell script?

Bookmark this question. Show activity on this post. ./hive -e "use telecom;insert overwrite local directory '/tmp/result' select avg(a) from abc;" ./hive --hiveconf MY_VAR =`cat /tmp/result/000000_0`;

How do I store hive query results?

To directly save the file in HDFS, use the below command: hive> insert overwrite directory '/user/cloudera/Sample' row format delimited fields terminated by '\t' stored as textfile select * from table where id >100; This will put the contents in the folder /user/cloudera/Sample in HDFS. Show activity on this post.


2 Answers

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> 
like image 105
az3 Avatar answered Sep 21 '22 00:09

az3


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.

like image 21
pyfunc Avatar answered Sep 18 '22 00:09

pyfunc