Apache Pig Foreach Operator - Apache Pig

Why Apache Pig Foreach Operator is used?

The FOREACH operator of Apache pig is used to create unique as per the available column data.


Here’s the syntax of FOREACH operator.


Let’s have a file named student_details.txt in the HDFS directory /pig_data/ as shown below.
Let’s upload this file into Pig with the relation name student_details as shown below.
Let’s take id, age, and city values of each student from the relation student_details and store it into another relation named foreach_data using the foreach operator as mentioned below.


Now, verify the relation foreach_data using the DUMP operator as mentioned below.


It will deliver the below mentioned output, displaying the contents of the relation foreach_data.

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Apache Pig Topics