PIG COMMANDS WITH EXAMPLES-PART -2

PIG COMMANDS WITH EXAMPLES-PART -2

GROUP OPERATOR:

The simpler of these operators is GROUP. Continuing with the same set of relations

grunt> Emp_grouped = GROUP Emp BY salary;


grunt> DUMP Emp_grouped;

Group Output:

FOREACH OPERATOR:

 

One of the key uses of Pig is data transformation. You can define a new relation based on the fields of an existing relation using the FOREACH command
grunt> foreach_Emp = FOREACH Emp GENERATE id,name;

grunt> dump foreach_Emp;

Foreach Output:

JOIN OPERATOR:

which groups
together tuples from multiple relations . It functions much like a join. For example, let’s Join Emp and Customer on the first column.

grunt> Emp_self = join Emp by id, Customer by id;

grunt> DUMP Emp_self;
Self Join Output:
 

By default behavior of join as an outer join, and
the join keyword can modify it to be left outer join, right outer join, or inner join.Another way to do inner join in Pig is to use the JOIN operator.
Empcust_left = join Emp by id left outer, Customer by id;

 

grunt> dump Empcust_left;
Left Outer Join Output:
Empcust_right = join Emp by id right outer, Customer by id;
grunt> dump Empcust_right;
Right Outer Join Output:
Empcust_full = join Emp by id full outer, Customer by id;
grunt> dump Empcust_full;
Full Outer Join Output:

DISTINCT OPERATOR:

 grunt> Emp2_dist = DISTINCT Emp2;

grunt> dump Emp2_dist;

DISTINCT Output:

LIMIT OPERATOR:

grunt> limit_data = LIMIT Emp 3;

grunt> dump limit_data;

 

LIMIT Output:

 

Category: PIG