1
votes

how do I concat a variable with some hardcode value in PIG

A = LOAD 'data' as (f1:chararray, f2:chararray, f3:chararray);

X = FOREACH A GENERATE CONCAT("BIG",f3);

Expected output :

(apache,open,BIGsource)

(hadoop,map,BIGreduce)

(pig,pig,BIGlatin)

1

1 Answers

1
votes

Pig doesn't support double quotes, so you need to change the hard-coded value from double to single quotes.

X = FOREACH A GENERATE f1,f2,CONCAT('BIG',f3);

Update:
You can use REPLACE function to remove the double quotes from input.
sample example below

data

"apache","open","source"
"hadoop","map","reduce"
"pig","pig","latin"

PigScript:

A = LOAD 'data' USING PigStorage(',') AS (f1:chararray, f2:chararray, f3:chararray);
B = FOREACH A GENERATE REPLACE(f1,'"',''),REPLACE(f2,'"',''),CONCAT('BIG',REPLACE(f3,'"',''));
DUMP B

Output:

(apache,open,BIGsource)
(hadoop,map,BIGreduce)
(pig,pig,BIGlatin)