PIG COMMANDS WITH EXAMPLES-PART -1

PIG COMMANDS WITH EXAMPLES-PART -1

create Four files
With name of Emp.txt,Emp2.txt,customer.txt,and orders.txt
Emp.txt file Data:
101,reema,20000
102,sangeeta,30000
103,ajay,35000
104,sanjay,25000
105,vijay,28000
106,abhay,22000
Emp2.txt files Data:

101,reema,20000
102,sangeeta,30000
103,ajay,35000
104,sanjay,25000
102,sangeeta,30000
103,ajay,35000
104,sanjay,25000
102,sangeeta,30000
103,ajay,35000
104,sanjay,25000
102,sangeeta,30000
103,ajay,35000
104,sanjay,25000
102,sangeeta,30000
103,ajay,35000
104,sanjay,25000
102,sangeeta,30000

 

customers.txt files Data:

1,priya,32,Ahmedabad,2000.00
2,madhulata,25,Delhi,1500.00
3,omnath,23,Kota,2000.00
4,reeja,25,Mumbai,6500.00
5,rahul,27,Bhopal,8500.00
6,kushagra,22,MP,4500.00
7,tania,24,Indore,10000.00

 

orders.txt files Data:

102,2009-10-08 00:00:00,3,3000
100,2009-10-08 00:00:00,3,1500
101,2009-11-20 00:00:00,2,1560
103,2008-05-20 00:00:00,4,2060

Copying files from local file system to hdfs(hadoop).

 

Load data from a file into a relation. Uses the PigStorage load function as default unless specified otherwise with the USING option. The data can be given a schema using the AS option

Display the content of a relation. Use mainly for debugging. The relation should be small enough for printing on screen.

Display output of Emp:

 

Display output of Emp2:

 

 

Display output of Customer:

 

 

Display output of Orders:

 

 

UNION combines multiple relations together


grunt> Emp_Uni = UNION Emp, Emp2;

whereas SPLIT partitions a relation into multiple ones

grunt> SPLIT Emp INTO Emp11 if salary<30000, Emp12 if (20000<salary and 25000<salary);

Display Output of Emp11

 

Display Output of Emp12

 

The FILTER operator alone trims a relation down to only tuples that pass a certain test n


grunt> Emp_filter = FILTER Emp BY id == 103;

Display output of Filter:


grunt> DUMP Emp_filter;

September 24, 2014 / PIG
Category: PIG