-1

I'm trying to load a .csv file on disk into Hive.

Per this answer on StackOverflow, I created the table using the following query:

CREATE TABLE mytable 
(
id_number STRING, 
country STRING
) 
ROW FORMAT DELIMITED FIELDS TERMINATED BY ','
STORED AS TEXTFILE;

I then dumped the data from the file into Hive using the following query:

LOAD DATA LOCAL INPATH /mytable.csv OVERWRITE INTO TABLE mytable;

Unfortunately, the result table in hive consisted of a single row, where each element (shown below) is a smashed-together version of a row from the .csv file:

"aDXLS23M\tRussia"

I've been stuck on this for hours and can't figure out how to get hive to recognize the column separators in the .csv file. Any suggestions?

Thanks in advance.

Community
  • 1
  • 1
monkeybiz7
  • 4,898
  • 5
  • 21
  • 35

2 Answers2

1

Do this in hive shell:

DROP TABLE IF EXISTS mytable;

CREATE TABLE mytable (id_number STRING,country STRING) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' STORED AS TEXTFILE;

LOAD DATA LOCAL INPATH /mytable.csv OVERWRITE INTO TABLE mytable;

Just replace , with \t in your create command. If possible post your csv contents.

If it still didn't work, try removing overwrite from load data command like this:

LOAD DATA LOCAL INPATH /mytable.csv INTO TABLE mytable;
Rajesh N
  • 2,554
  • 1
  • 13
  • 17
-1

To load .CSV data file into hive table

eg. create table salary(yrsofexp decimal (10,2), salary decimal(10,2)) row format delimited fields terminated by ',' stored as textfile;

LOAD DATA LOCAL INPATH '/home/Test/SalaryData.csv'
OVERWRITE INTO TABLE salary;

it's loading perfectly

Serjik
  • 10,543
  • 8
  • 61
  • 70