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.

Syntax

Here’s the syntax of FOREACH operator.

Example

Let’s have a file named student_details.txt in the HDFS directory /pig_data/ as shown below.
student_details.txt
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.

Verification

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

Output

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

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

Apache Pig Topics