Search code examples
hadoopapache-pig

Issue with AVG() function in Pig Latin


I am trying to generate an AVG() of performances (double) that are listed in a data set. I am receiving an ERROR 1066: Unable to open iterator for alias TEST exception, which I assume to be because TEST is empty and cannot be iterated over.

code:

flat_bus = FOREACH buss GENERATE near, name, FLATTEN(categories) AS category, stars;

bus_grouped = GROUP flat_bus BY category;

category_avg = FOREACH bus_grouped GENERATE group as grp, AVG(bus_grouped.stars);

TEST = LIMIT category_avg 10;

DUMP TEST;

I tested the group function and it successfully dumps as seen below: enter image description here


Solution

  • Should get stars from flat_bus

    category_avg = FOREACH bus_grouped GENERATE group as grp, AVG(flat_bus.stars);