Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import data flat files in hive without defining hive table structure

Can I import CSV or any other flat files in to hive without creating and defining table structure first in hive. Say my csv file is having 200 columns and needs to be imported into hive table. So I have to first create a table in hive and define all the column names and datatype within that hive table and import. Is there any way in which I can directly import in to hive and it automatically creates tables structure from first line say, similar to sqoop import?

like image 812
user1627563 Avatar asked Sep 06 '12 06:09

user1627563


People also ask

How do I import data into Hive?

Navigate to the file you want to import, right-click it, select Import into Hive, and select how to import it: Import as CSV, Import as Apache Avro, or Import as Apache Parquet.


2 Answers

use sqoop with a "hive-import" switch & it will create your table for you http://archive.cloudera.com/cdh/3/sqoop/SqoopUserGuide.html#_importing_data_into_hive

like image 164
rICh Avatar answered Sep 19 '22 14:09

rICh


Check your hive-site.xml for the value of the property javax.jdo.option.ConnectionURL. If you do not define this explicitly, the default value will use a relative path for creation of hive metastore (jdbc:derby:;databaseName=metastore_db;create=true) which will be different depending upon where you launch the process from. This would explain why you cannot see the table via show tables.

The way to overcome it would be to define this property value in your hive-site.xml using an absolute path

like image 28
user1631977 Avatar answered Sep 19 '22 14:09

user1631977