Pig: Unable to load data using PigStorage Pig: Unable to load data using PigStorage hadoop hadoop

Pig: Unable to load data using PigStorage


The reason is, both the tuple and each fields inside the tuple have the same delimiter(','). In this case, pig will parse the input and failed in the schema conversion.

You can see the below logs in your console

"Unable to interpret the value in field being converted to type tuple, caught ParseException <Unexpect end of tuple> field discarded"

To fix this issue

  1. You need to change the tuple delimiter ',' to something different. In the below example i have used '#' as delimiter instead of ','. You can use any delimiter other than (',')

  2. Your input file have two tuples but you defined only one tuple in the load schema, so you need to define the other one also.

Sample example:

input

(Eric,Ack,27,M)#(Jeremy,Ross,29,F)(Jenny,Dicken,27,F)#(Vijay,Sampath,40,M)(Angs,Dicken,28,M)#(Venu,Rao,28,M)(Mahima,Mohanty,29,F)#(Kenny,Oath,28,M)

Pigscript:

tuple_record = LOAD '~/Documents/Pig_Tuple.txt' USING PigStorage('#') AS (details:tuple(firstname:chararray,lastname:chararray,age:int,sex:chararray), details1:tuple(firstname1:chararray,lastname1:chararray,age1:int,sex1:chararray));DUMP tuple_record;

output:

((Eric,Ack,27,M),(Jeremy,Ross,29,F))((Jenny,Dicken,27,F),(Vijay,Sampath,40,M))((Angs,Dicken,28,M),(Venu,Rao,28,M))((Mahima,Mohanty,29,F),(Kenny,Oath,28,M))

Update:
How to change the delimiter ',' to something different
Option1: Using sed
This is very easy option, by using sed command replace the '),(' pattern to ')#(' pattern, so that the delimiter will be changed from ',' to '#' in the same input file.(Note:take backup of your input file before executing this sed script)

>> sed -i -- 's/),(/)#(/g' inputFile

Option2: Slight modification in the pigscript without changing the delimiter
Pigscript:

--Read each input line as chararrayA = LOAD 'inputFile' AS (line:chararray);--Remove the character '(',')' from the inputB = FOREACH A GENERATE FLATTEN(REPLACE(line,'[)(]+','')) AS (newline:chararray);--Split the input using ',' as delimiter, 8 refer to total number of fieldsC = FOREACH B GENERATE FLATTEN(STRSPLIT(newline,',',8)) AS (firstname1:chararray,lastname1:chararray,age1:int,sex1:chararray,firstname2:chararray,lastname2:chararray,age2:int,sex2:chararray);--Group the fields and form tuples D = FOREACH C GENERATE TOTUPLE(firstname1,lastname1,age1,sex1) AS details1,TOTUPLE(firstname2,lastname2,age2,sex2) AS details2;--Now you can do whatever you want.E = FOREACH D GENERATE details1.firstname1,details2.firstname2;DUMP E;


Please check the complex scheme section of the Pig Documentation

cat data;(3,8,9) (mary,19)(1,4,7) (john,18)(2,5,8) (joe,18)A = LOAD data AS (F:tuple(f1:int,f2:int,f3:int),T:tuple(t1:chararray,t2:int));DESCRIBE A;A: {F: (f1: int,f2: int,f3: int),T: (t1: chararray,t2: int)}DUMP A;((3,8,9),(mary,19))((1,4,7),(john,18))((2,5,8),(joe,18))