Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

How to export the header of hive table into CSV file?

How to export the header of hive table into CSV file?

 
4 REPLIES 4

Re: How to export the header of hive table into CSV file?

Expert Contributor

Venkat Please try this :

hive -e 'set hive.cli.print.header=true; select * from your_Table' | sed 's/[\t]/,/g'  > /home/yourfile.csv

Original answer https://stackoverflow.com/questions/17086642/how-to-export-a-hive-table-into-a-csv-file

Re: How to export the header of hive table into CSV file?

For this command I getting only the header.I want both header and data in the csv file

Re: How to export the header of hive table into CSV file?

Expert Contributor

Venkat

You should be getting both header and data with this command. I have just added "hive.cli.print.header=true" to print header along with data.

hive -e 'set hive.cli.print.header=true; select * from your_Table' | sed 's/[\t]/,/g' > /home/yourfile.csv

Whats the result you are seeing if you just do "select * from your_Table"? Does the table have the data?

Re: How to export the header of hive table into CSV file?

Sorry @ssharma it is working but when I trying like this

  1. hive -e 'set hive.cli.print.header=true; create table test row format delimited fields terminated by '|' as select * from test1'>/home/yourfile.csv in this scenario it only showing the header not the whole data csv file
Don't have an account?
Coming from Hortonworks? Activate your account here