Pigoperations

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

LOAD

relation_name = LOAD ‘/path’ pigfuction as(scheme);

STORE
STORE relation_name into ‘/path’ using PigStorage(‘,’);

GROUP
New_relationname = GROUP old_relation by field;

GROUP With Multiple fields


New_relationname = GROUP old_relation by (field1,field2);

GROUP ALL
New_relationname = GROUP old_relation all;

COGROUP
New_relationname = COGROUP old_relation1 by field,
old_relation2 by field,;

UNION
New_relationname = UNION relation1, relation2;
CROSS
New_relationname = CROSS relation1, relation2;
FOREACH
To select needed columns
Newrelation = FOREACH oldrelation GENERATE fields;

Cus5 = LOAD ‘/testing/customer5.txt’ using PigStorage(‘,’)


as(id:int,firstname:chararray,lastname:chararray,age:int,prof
ession:chararray,location:chararray,salary:long);

Cus5out = FOREACH cus5 GENERATE $1,$3,$5;

STORE cus5out into ‘/testing/cus5output’ using


PigStorage(‘,’);
In cus5output directory will have 2 file successfile and result
file

LIMIT
To select needed rows

Newrelation = LIMIT oldrelation number;


ORDER
To sort a data set
Newrelationname = ORDER oldrelation by field asc/desc;

Cusorder = ORDER Cus5out by location;


FILTER
To filter a dataset
Newrelation = FILTER oldrelation by field condition;

Cus5 = LOAD ‘/testing/customer5.txt’ using PigStorage(‘,’)


as(id:int,firstname:chararray,lastname:chararray,age:int,prof
ession:chararray,location:chararray,salary:long);
Cusfilter = FILTER Cus5 by age <= 40;
PIG EVALUATION FUNCTIONS
COUNT, MAX, MIN, SUM, AVG
Sample4.txt

1.age above 23 – Firstname,Lastname,age,Location


2.Working in Chennai- fname,lname,age,phone
3.Working in Chennai age max 1 employeee
4.Chennai age Min 5 employees

You might also like