尝试使用apache pig聚合数据时出错

cwdobuhd  于 2021-06-01  发布在  Hadoop
关注(0)|答案(1)|浏览(414)

这是我正在运行的代码:

bigrams = LOAD 's3://******' AS (bigram:chararray, year:int, occurrences:int, books:int);
bg_tmp = filter bigrams BY (occurrences >= 300) AND (books >= 12);
bg_tmp_2 = GROUP bg_tmp ALL;
occ_cnt = FOREACH bg_tmp_2 GENERATE bigram, SUM(bg_tmp_2.occurrences);
x = LIMIT occ_cnt 100;
DUMP x;

这就是我在计算时遇到的错误 occ_cnt ```
81201 [main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1200: Pig script failed to parse: <line 5, column 48> Invalid scalar projection: bg_tmp_218/10/26 16:05:07 ERROR grunt.Grunt: ERROR 1200: Pig script failed to parse: <line 5, column 48> Invalid scalar projection: bg_tmp_2
Details at logfile: /mnt/var/log/pig/pig_1540569826316.log

我不知道为什么会这样。我在aws emr上使用apachepig0.17.0和hadoop2.8.4
jdzmm42g

jdzmm42g1#

我会把你的问题改写为

bg_tmp_2 = GROUP bg_tmp by (bigram);
occ_cnt = FOREACH bg_tmp_2 GENERATE group, SUM(bg_tmp.occurrences);

替换group all,因为我认为您需要每个bigram条目的总和。用bg\u tmp替换bg\u tmp2,因为您希望在bg\u tmp\u 2关系中引用bg\u tmp包。
(如果运行“descripe bg\u tmp\u 2”,您将看到以下模式)

bg_tmp_2: {group: chararray,bg_tmp: {(bigram: chararray,year: int,occurrences: int,books: int)}}

相关问题