Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hive: writing column headers to local file?

Tags:

syntax

hive

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?

Insert overwrite local directory 'tmp/blah.blah' select * from table_name; 

Also, separate question: Is StackOverflow the best place to get Hive Help? @Nija, has been very helpful, but I don't to keep bothering them...

like image 432
CMaury Avatar asked Apr 13 '11 23:04

CMaury


People also ask

How will you store the results of hive query in a file?

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

Try

set hive.cli.print.header=true; 
like image 135
iggy Avatar answered Sep 21 '22 14:09

iggy


Yes you can. Put the set hive.cli.print.header=true; in a .hiverc file in your main directory or any of the other hive user properties files.

Vague Warning: be careful, since this has crashed queries of mine in the past (but I can't remember the reason).

like image 42
Dan B Avatar answered Sep 22 '22 14:09

Dan B