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

8zzbczxx  于 2021-06-21  发布在  Pig
关注(0)|答案(1)|浏览(301)
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;

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

qmelpv7a

qmelpv7a1#

在属性前面加上 (chararray) 。假设要将zipcode转换为string。请参阅此处以获取转换文档

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

按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;

相关问题