Reputation: 5282
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?
Upvotes: 0
Views: 920
Reputation: 1959
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"
Upvotes: 1