Create Hive Tables From CSV Files - Cloudera Community - 204532

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
  • Create Hive tables from CSV files
Options Options

Create Hive tables from CSV files

  • Apache Hadoop
  • Apache Hive
avatar author-rank dhieru Expert Contributor

Created ‎10-02-2017 10:51 PM

10-02-2017 10:51:51

Hi All,

I have been creating Hive tables from CSV files manually copying the column names and pasting in a Hive create table script.

However I have at least 300 CSV files. I don want to repeat the same process for 300 times. Is there anyway I can autmatically create hive table creation script using the column headers as column names?

Thanks in advance

Reply 33,931 Views 0 Kudos
  • All forum topics
  • Previous
  • Next
5 REPLIES 5 avatar author-rank melvinmendoza Visitor

Created ‎10-03-2017 12:06 AM

10-03-2017 12:06:28

@dhieru singh is your CSV file have the same format? if yes, you might consider to use

CREATE EXTERNAL TABLE table_name ( colA ... colB.. ) partitioned by .. location ... msck repair table table_name alter table table_name add partition ...

every time you have a new file you just run and generate

msck repair table table_name alter table table_name add partition ... Reply 17,486 Views 0 Kudos avatar author-rank dhieru Expert Contributor

Created ‎10-03-2017 05:14 PM

10-03-2017 05:14:18

@mel mendoza Thanks for the help. Unfortunately all the CSV files have different columns.

Reply 17,486 Views 0 Kudos avatar author-rank Shu_ashu Master Guru

Created on ‎10-03-2017 05:54 PM - edited ‎08-17-2019 09:59 PM

10-03-2017 05:54:10

@dhieru singh,

Another way is, Use Ambari and click on HiveView as show in the below screenshot.

40627-ambari-view.png

then click on UploadTable and if your csv file is in local then click on choose file

40628-upload.png

if you want to get column names from headers then click on the gear symbol after Filetype dropdown

40629-header.png

The table will gets all the column names from csv file headers.

Select the database where do you want to create the table and change the table name if you want to change.

Then click on UploadTable button located at left on the screen.

Reply 17,486 Views 0 Kudos avatar author-rank dhieru Expert Contributor

Created ‎10-03-2017 06:09 PM

10-03-2017 06:09:02

@Shu Thanks let me try it and will update you Thanks again

Reply 17,486 Views 0 Kudos avatar author-rank Seaport Expert Contributor

Created ‎04-30-2019 05:06 PM

04-30-2019 05:06:45

I am facing the same issue right now. My current approach is to have a script to read the first line of all my csv files and then transform the first-line text into create sql statement.

I wonder whether this is some built-in solution from HDP.

Reply 17,486 Views 0 Kudos Post Reply Announcements 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 ... Community Announcements Welcome to the Cloudera Community! View More Announcements

Tag » How To Add Header Column To Hive Table Csv