使用sum()时出现pig脚本错误

y0u0uwnf  于 2021-06-21  发布在  Pig
关注(0)|答案(1)|浏览(348)

我在运行这个pig脚本时遇到以下错误…请帮助!!!提前谢谢。

"ERROR 1000: Error during parsing. Scalars can be only used with projections"

MOVIES = LOAD '/MOVIES' using PigStorage(',') as (mid:double, mn:chararray, yr:int, rt:float, dr:int);

Filter11 = filter MOVIES by $2 >= 1950;

Filter12 = filter Filter11 by $2 <= 1960;

Group1 = group Filter12 by yr;

Count1 = foreach Group1 generate group, COUNT(Filter12);

Sum1 = foreach Count1 generate SUM(Group1);

DUMP Sum1;
iibxawm4

iibxawm41#

将两个过滤条件结合起来,在最后一步中,将计数相加,即count(filter11)或$1。

MOVIES = LOAD '/MOVIES' using PigStorage(',') as (mid:double, mn:chararray, yr:int, rt:float, dr:int);
Filter11 = filter MOVIES by ($2 >= 1950 and $2 <= 1960);
Group1 = group Filter11 by yr;
Count1 = foreach Group1 generate group, COUNT(Filter11);
Sum1 = foreach Count1 generate SUM($1);
DUMP Sum1;

相关问题