R Padmaja
R Padmaja

Reputation: 11

how to convert attribute of a relation into string in pig

c1 = LOAD 'hdfs://localhost:9000/PigData/patient.txt' USING PigStorage(',') 
as (age:int,gender:chararray,zipcode:int); 
c2 = LOAD 'hdfs://localhost:9000/PigData/att1' USING PigStorage(',') as (att:chararray,cnt:int);
res = FOREACH c2 generate $0;
%declare zip res.$0;
final = group c1 by $zip;
dump final;

i want to store atrribute as a vaue in a variable , then group the data with the help of that variable without mentioning the value directly..

Upvotes: 1

Views: 2476

Answers (1)

nobody
nobody

Reputation: 11080

Prefix the attribute with (chararray).Assuming you would like to cast zipcode to string.See here for cast documentation

c2 = FOREACH c1 GENERATE c1.age,c1.gender,(chararray)c1.zipcode;
DESCRIBE C2;

Group by zipcode

c1 = LOAD 'hdfs://localhost:9000/PigData/patient.txt' USING PigStorage(',') as (age:int,gender:chararray,zipcode:int);
c2 = LOAD 'hdfs://localhost:9000/PigData/att1' USING PigStorage(',') as (att:chararray,cnt:int);
final = group c1 by c1.zipcode;
dump final;

Upvotes: 1

Related Questions