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;
我想将atrribute存储为变量中的vaue,然后在该变量的帮助下对数据进行分组,而不直接提及该值。
答案 0 :(得分:0)
使用(chararray)
前缀属性。假设您要将zipcode转换为string.See here以获取演员文档
c2 = FOREACH c1 GENERATE c1.age,c1.gender,(chararray)c1.zipcode;
DESCRIBE C2;
按邮政编码分组
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;