Apache pig 如何在pig中将关系的属性转换为字符串

Apache pig 如何在pig中将关系的属性转换为字符串,apache-pig,Apache Pig,我想将属性作为vaue存储在变量中,然后在该变量的帮助下对数据进行分组,而不直接提及值。在属性前面加上(chararray)。假设您想将zipcode转换为字符串。有关转换文档,请参阅 c1 = LOAD 'hdfs://localhost:9000/PigData/patient.txt' USING PigStorage(',') as (age:int,gender:chararray,zipcode:int); c2 = LOAD 'hdfs://localhost:9000/Pig

我想将属性作为vaue存储在变量中,然后在该变量的帮助下对数据进行分组,而不直接提及值。

在属性前面加上
(chararray)
。假设您想将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);
res = FOREACH c2 generate $0;
%declare zip res.$0;
final = group c1 by $zip;
dump final;
按zipcode分组

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

谢谢你的帮助reply@RPadmaja您不需要该语句。只需使用zipcode来分组。res relation具有值(zipcode),我想将c1关系与此res值分组。%声明邮政编码为$0;我尝试了这个代码,但我在这里得到了错误。
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;