How To Export The Header Of Hive Table Into CSV File?

logo
  • Community
  • Training
  • Partners
  • Support
Support Questions Find answers, ask questions, and share your expertise All communityThis categoryThis boardCommunity ArticlesUsers cancel Turn on suggestions Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type. Showing results for  Show  only  | Search instead for  Did you mean:  Advanced Search Announcements Now Live: Explore expert insights and technical deep dives on the new Cloudera Community Blogs — Read the Announcement
  • Cloudera Community
  • Support
  • Support Questions
  • How to export the header of hive table into CSV fi...
Options Options

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

  • Apache Hive
avatar author-rank chiranjeevivenk Explorer

Created ‎06-16-2018 08:01 PM

06-16-2018 08:01:32 Reply 26,419 Views 0 Kudos
  • All forum topics
  • Previous
  • Next
4 REPLIES 4 avatar author-rank ssharma Super Collaborator

Created ‎06-18-2018 05:18 AM

06-18-2018 05:18:55

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

Reply 19,887 Views 2 Kudos avatar author-rank chiranjeevivenk Explorer

Created ‎06-20-2018 05:58 PM

06-20-2018 05:58:04

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

Reply 19,887 Views 0 Kudos avatar author-rank ssharma Super Collaborator

Created ‎06-21-2018 01:32 AM

06-21-2018 01:32:57

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?

Reply 19,887 Views 0 Kudos avatar author-rank chiranjeevivenk Explorer

Created ‎06-21-2018 02:20 PM

06-21-2018 02:20:05

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
Reply 19,887 Views 0 Kudos Post Reply Announcements Community Announcements December 2025 Community Highlights Community Announcements Announcing the Launch of Cloudera Community Blogs Community Announcements October / November 2025 Community Highlights What's New @ Cloudera Announcing Cloudera Streaming Analytics - Kubernetes Operato... What's New @ Cloudera Announcing Cloudera Streams Messaging - Kubernetes Operator ... View More Announcements

Tag » How To Adding Column Headers To Hive Result Set