gpt4 book ai didi

hadoop - 比较Pig中的变量

转载 作者:行者123 更新时间:2023-12-02 20:48:32 25 4
gpt4 key购买 nike

我有三个变量,分别是redcount,greencount和bluecount(已经在同一个 pig 程序中计算过)
我想比较它们的值,并显示三个最大的名称。

现有代码如下

countryflags = LOAD '/home/rahul/countryprojectdata/Country.txt' USING PigStorage(',') AS (country:chararray,landmass:int,zone:int,area_1ksqmtr:int,popoulation_million:int,language:int,religion:int,n_vbars:int,n_stripes:int,n_colors:int,redcolour:int,greencolour:int,bluecolour:int,goldcolour:int,whitecolour:int,blackcolour:int,orangecolour:int,mainhue:chararray,n_circles:int,n_upcrosses:int,n_digonalcrosses:int,n_quarteredsections:int,n_sunstars:int,crescent:int,triangle:int,icon:int,animate:int,text:int,topleftcolour:chararray,bottomrightcolour:chararray);

grpred = GROUP countryflags BY redcolour;
redcount = FOREACH grpred GENERATE SUM(countryflags.redcolour);

grpgreen = GROUP countryflags BY greencolour;
greencount = FOREACH grpgreen GENERATE SUM(countryflags.greencolour);

grpblue = GROUP countryflags BY bluecolour;
bluecount = FOREACH grpblue GENERATE SUM(countryflags.bluecolour);

请帮忙。

最佳答案

UNION这三个关系,排序并获得最高记录。假设您只想要颜色的名称和最大的计数。

grpred = GROUP countryflags BY redcolour;
redcount = FOREACH grpred GENERATE 'red' as name,SUM(countryflags.redcolour) as red_sum;

grpgreen = GROUP countryflags BY greencolour;
greencount = FOREACH grpgreen GENERATE 'green' as name,SUM(countryflags.greencolour) green_sum;

grpblue = GROUP countryflags BY bluecolour;
bluecount = FOREACH grpblue GENERATE 'blue' as name,SUM(countryflags.bluecolour) as blue_sum;

A = UNION redcount,greencount,bluecount;
B = ORDER BY $1 DESC; -- Note: $1 because,we are creating a new column name else $0;
C = LIMIT B 1;
DUMP C;

关于hadoop - 比较Pig中的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46918396/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com