[Solved-1 Solution] Projecting Grouped Tuples in Pig

What is tuple ?

  • A Pig relation is a bag of tuples. A Pig relation is similar to a table in a relational database, where the tuples in the bag correspond to the rows in a table
  • Tuples can be grouped by using GROUP operator.


If you have a collection of tuples of the form (t,a,b) that we want to group by b in Pig. Once grouped, you may to filter out b from the tuples in each group and generate a bag of filtered tuples per group.

As an example, assume we have (1,2,1) (2,0,1) (3,4,2) (4,1,2) (5,2,3)

The pig script would produce {(1,2),(2,0)} {(3,4),(4,1)} {(5,2)}

How do we go about producing this result?

Solution 1:

If one has tuples of the form (t,a,b) and wants to drop b after the group by, it is done this way.

Here is the following code that groups the tuples

grouped = GROUP  tups  BY b;
result  = FOREACH  grouped  GENERATE tup.(t,a);

Related Searches to Projecting Grouped Tuples in Pig