...

Big Data - Apache Pig

Back to Course

Lesson Description


Lession - #474 Apache pig UNION Operator


The UNION operator of Pig Latin is utilized to combine the content of two relations. To perform UNION operation on two relations, their columns and areas should be identical.

The syntax of UNION operator is shown below:


 
 
 grunt> Relation_name3 = UNION Relation_name1, Relation_name2;
 


Example

Assume that we have a files named student_details1.txt and student_details2.txt in the HDFS directory /pig_data/ as shown below.

student_details1.txt


1 aaa 74385738 delhi 21
4 ggg 74824727 goa 21



student_details2.txt

1 aaa 74385738 delhi 21
2 bbb 76349948 mumbai 22
4 ggg 74824727 goa 21
5 hhh 74843847 pune 22
7 lll 76485838 goa 26



Writing UNION Operator Operator


grunt> student = UNION student1, student2;



Output

Student.txt

1 aaa 74385738 delhi 21
2 bbb 76349948 mumbai 22
3 ddd 87493589 pune 23
4 ggg 74824727 goa 21
5 hhh 74843847 pune 22
6 uuu 76347242 delhi 24
7 lll 76485838 goa 26