0

I read through this question, which is essentially what I'm trying to do. For a couple of reasons this approach seems to most straighforward for my need:

DROP TABLE IF EXISTS TestHiveTableCSV; 
CREATE TABLE TestHiveTableCSV 
ROW FORMAT DELIMITED 
FIELDS TERMINATED BY ',' 
LINES TERMINATED BY '\n' AS
 SELECT Column List FROM TestHiveTable;

However when I move that file from HDFS onto my local filesysyem I lose the headers. Any idea how to add headers?

Community
  • 1
  • 1
ADJ
  • 4,892
  • 10
  • 50
  • 83

1 Answers1

1

use set hive.cli.print.header=true;

usage

hive -S -e ' set hive.cli.print.header=true;select * from table ' >> outputfile

Or you can use this approach as well

hive -f ${HIVEFILE1} -hiveconf hive_database=${HIVE_DATABASE} -hiveconf CURRENT_DATE='2014-05-05' | sed 's/[\t]/,/g' > yourfile.csv

where Hivefile1 has the hive query "set hive.cli.print.header=true;select * from table"

yoga
  • 1,929
  • 2
  • 15
  • 18
  • hive -S -e ' set hive.cli.print.header=true;select * from table ' >> outputfile – yoga Dec 16 '15 at 20:25
  • Or you can use this approach as well hive -f ${HIVEFILE1} -hiveconf hive_database=${HIVE_DATABASE} -hiveconf CURRENT_DATE='2014-05-05' | sed 's/[\t]/,/g' > yourfile.csv where Hivefile1 has the hive query "set hive.cli.print.header=true;select * from table" – yoga Dec 16 '15 at 20:32
  • If I follow the initial suggestion "hive -S -e..." the file created is no longer a comma separated. – ADJ Dec 16 '15 at 20:39