Search code examples
sqlhadoopapache-pig

Convert SQL query to Pig query


I am working w/ Pig in Hadoop and have need to convert the following SQL code to PigLatin:

SELECT lo_discount, COUNT(lo_extendedprice)
FROM lineorder
GROUP BY lo_discount;

After loading the lineorder table, this is what I've got so far, but unfortunately it is not working:

data = FOREACH lineorder GENERATE lo_discount, lo_extendedprice;
dataG = GROUP data BY lo_discount;
ans0 = FOREACH dataG GENERATE dataG.lo_discount, COUNT(dataG.lo_extendedprice);

Can anyone help me how to do this? Thanks!


Solution

  • Modify the last pig statment to

    ans0 = FOREACH dataG GENERATE group, COUNT(data);