Apache pig 在apache pig中添加两列行

Apache pig 在apache pig中添加两列行,apache-pig,Apache Pig,找出前五名的国家与酒吧和条纹的总和在国旗 输入为: 我尝试了以下代码1: grunt> A =load 'mapreduce/flagdata.txt' using PigStorage(',') as (name: chararray, landmass: int, zon: int, area: int, population: int, language: int, religion: int, bars: int, stripes: int, colours: int, red:

找出前五名的国家与酒吧和条纹的总和在国旗

输入为:

我尝试了以下代码1:

grunt> A =load 'mapreduce/flagdata.txt' using PigStorage(',') as (name: chararray, landmass: int, zon: int, area: int, population: int, language: int, religion: int, bars: int, stripes: int, colours: int, red: int, green: int, blue: int, gold: int, white: int, black: int, orange: int, mainhue: chararray, circles: int, crosses: int, saltires: int, quarters: int, sunstairs: int, crescent: int, triangle: int, icon: int, animate: int, text: int, topleft:chararray, botleft: chararray);
grunt> cnt = foreach A generate A.$0, (A.$7+A.$8);//(the same output even if used column name like A.name,A.bars)//
grunt> ord = order cnt by $1 desc;
grunt> lm = limit ord 5;
grunt> dump lm;
代码1的实际输出:

ERROR org.apache.pig.tools.pigstats.SimplePigStats - ERROR 0: Scalar has more than one row in the output. 1st : (Afghanistan,5,1,648,16,10,2,0,3,5,1,1,0,1,1,1,0,green,0,0,0,0,1,0,0,1,0,0,black,green), 2nd :(Albania,3,1,29,3,6,6,0,0,3,1,0,0,1,0,1,0,red,0,0,0,0,1,0,0,0,1,0,red,red)
[main] ERROR org.apache.pig.tools.pigstats.PigStatsUtil - 1 map reduce job(s) failed!
代码2:

grunt> cnt = foreach A generate A::$0, (A::$7+A::$8) as total;
<line 6, column 28>  Unexpected character '$'
[main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1200: <line 6, column 28>  Unexpected character '$'
grunt> cnt = foreach A generate A::name, (A::bars+A::stripes) as total;
[main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1025: 
<line 6, column 25> Invalid field projection. Projected field [A::name] does not exist in schema: name:chararray,landmass:int,zon:int,area:int,population:int,langu
age:int,religion:int,bars:int,stripes:int,colours:int,red:int,green:int,blue:int,gold:int,white:int,black:int,orange:int,mainhue:chararray,circles:int,crosses:int,
saltires:int,quarters:int,sunstairs:int,crescent:int,triangle:int,icon:int,animate:int,text:int,topleft:chararray,botleft:chararray.
预期产出为:

需要显示的前5个国家的名称与sumbars+条纹更大。单独列仅供参考


我得到了不同的输出,有时错误不能推断org.apache.pig.builtin.SUM的匹配函数是多个还是没有一个匹配。请使用显式强制转换。在修改上述代码时。请帮助获取两列的总和。

如果条形和条纹的数据类型为int,则只需使用“+”。总和对列进行操作。如果国家/地区列表是唯一的,则无需分组

cnt = foreach A generate name,(bars + stripes) as total;
ord = order cnt by $1 desc;
lm = limit ord 5;
dump lm;

它将错误显示为:org.apache.pig.tools.pigstats.simplePostStats-错误0:执行Name:Split-scope-181运算符键:scope-181:org.apache.pig.backend.executionengine.ExecutionException:错误0:标量在输出中有多行。即使在更改后,它也会显示相同的错误:errororg.apache.pig.tools.pigstats.SimplePostStats-错误0:标量在output.ERROR org.apache.pig.tools.grunt.grunt中有多行-错误1025:字段投影无效。架构中不存在投影字段[A::name]:@pavan您可以发布整个脚本吗?非常感谢您的帮助。更新了我尝试的整个脚本。如果需要任何其他信息,请告诉我。