Search code examples
apache-pig

What is the difference between `::` and `.` in pig?


What is the difference between :: and . in pig?

When do I use one vs the other?

E.g., I know that :: is need in join when a field exists in both aliases:

A = foreach (join B by (x), C by (y)) generate B::y as b_y, C::y as c_y;

and I need . when accessing group fields:

A = foreach (group B by (x,y)) generate group.x as x, group.y as y, SUM(B?z) as z;

However, do I pass B::z or B.z to SUM above instead of B?z?


Solution

  • IIRC you get :: as a side effect after some statements. You cannot bother about it, unless (as you mentioned) a name exists inside two different prefixes.

    The . is different in that you are going inside the structure. group.x as x, group.y as y is equivalent to FLATTEN(group)

    SUM(B?z) - here you should do SUM(B.z), to specify that you need a particular field to SUM.