如何将关系的属性转换为猪的字符串

问题描述 投票:0回答:1
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;

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

apache-pig
1个回答
0
投票

使用(chararray)为该属性添加前缀。假设您要将zipcode转换为string.See here for cast documentation

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;
© www.soinside.com 2019 - 2024. All rights reserved.