尝试使用Apache Pig聚合数据时出错

时间:2018-10-26 16:18:48

标签: hadoop apache-pig

这是我正在运行的代码:

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上使用Apache Pig 0.17.0和Hadoop 2.8.4

1 个答案:

答案 0 :(得分:1)

我会将您的查询重写为

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

替换GROUP ALL,因为我认为您需要每个二元组条目的SUM。 因为要在bg_tmp_2关系中引用bg_tmp BAG,所以用bg_tmp替换bg_tmp2。

(如果您运行“ describe bg_tmp_2”,则会看到以下架构)

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