Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export Hive Query Results

Tags:

hive

hiveql

hue

I'm new to hive and could use some tips.

I'm trying to export query results from hive as a csv. When I try to pipe them out of CLI like:

hive -e 'select * from table'>OutPut.txt

I get a text file that has all the records but doesn't have the column headers. Does anyone have a tip for how to export the query results with the column headers, to a csv file?

If I run the query in hue, and then download the results as a csv I get a csv with the column headers but no records. If anyone has a tip on how to download query results from hue with records and column headers, I would greatly appreciate it too.

like image 875
user3476463 Avatar asked Jun 01 '14 04:06

user3476463


People also ask

How do I export 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.


1 Answers

To export the column headers, you need to set the following in the hiverc file:

set hive.cli.print.header=true;

To get just the headers into a file, you could try the following:

hive -e 'set hive.cli.print.header=true; SELECT * FROM TABLE_NAME LIMIT 0;' > /file_path/file_name.txt

like image 61
visakh Avatar answered Oct 03 '22 05:10

visakh