Loading CSV file on Hive Table with String Array Loading CSV file on Hive Table with String Array hadoop hadoop

Loading CSV file on Hive Table with String Array


Couple of stuff :
You are missing definition for delimiter for collection items.
Also , I assume you expect you select * from article statement to return like below :

48  Snacks that Power Up Weight Loss    Aidan B. Prince ["Health&Fitness","Travel"]99  Snacks that Power Up Weight Loss    Aidan B. Prince ["Photo","Travel"]

I can give you an example and rest you can fiddle with it .Here is my table definition :

create table article (  id int,  name string,  author string,  genre array<string>)row format delimitedfields terminated by ','collection items terminated by '|';

And here is the data :

48,Snacks that Power Up Weight Loss,Aidan B. Prince,Health&Fitness|Travel99,Snacks that Power Up Weight Loss,Aidan B. Prince,Photo|Travel

Now do a load like :
LOAD DATA local INPATH '/path' OVERWRITE INTO TABLE article;and do select statement to check the result.

Most important point :
define delimiter for collection items and don't impose the array structure you do in normal programming.
Also, try to make the field delimiters different from collection items delimiters to avoid confusion and unexpected results.


In order to insert array of string in Hive table , we need to take care of below point.

 1. While creating Hive table.Collection items should be terminated by "," ('colelction.delim'=',',) 2. Data should be like that in CSV file  48  Snacks that Power Up Weight Loss    Aidan B. Prince Health&Fitness,TravelYou can modify file  by running below SED commands in follwing order: - sed -i 's/\[\"//g' filename - sed -i 's/\"\]//g' filename - sed -i 's/"//g' filename