pig tutorial - apache pig tutorial - Apache Pig - Union Operator - pig latin - apache pig - pig hadoop
What is Union Operator in Apache Pig ?
- The UNION operator of Pig Latin is used to merge the content of two relations.
- To perform UNION operation on two relations, their columns and domains must be identical.
- Joins in the same relation multiple relations
Syntax
The syntax of the UNION operator is
Example
Ensure that we have two files namely wikitechy_employee_data1.txt and wikitechy_employee_data2.txt in the /pig_data/ directory of HDFS as shown below.
wikitechy_employee_data1.txt
wikitechy_employee_data2.txt
And we have loaded these two files into Pig with the relations employee1 and employee2 as shown below.
Now merge the contents of these two relations using the UNION operator as given below.
Verification
Now verify the relation employee using the DUMP operator as given below.
Output
The following output, displaying the contents of the relation employee.