pig tutorial - apache pig tutorial - Apache Pig - Foreach Operator - pig latin - apache pig - pig hadoop
What is Foreach Operator in Apache Pig ?
- FOREACH gives us a simple way to apply transformations which is done based on columns.
- The FOREACH operator of Apache pig is used to create unique function as per the column data which is available.
- FOREACH operator evaluates an expression for each possible combination of values of some iterator variables, and returns all the results
- FOREACH operator generates data transformations which is done based on columns of data.
- The FOREACH operator is used to generate specified data transformations which is done based on the column data.
Pig Operations - Projection
- Generate new relations by projecting data of a relation
- Let us execute the instruction and… it seems that nothing happens!
- We had some tracing output with LOAD, DUMP, and ILLUSTRATE…
- Operate on data in bags inside a relation and then project
Syntax:
Example:
wikitechy_student_details.txt
- And we have loaded this file into Pig with the relation name wikitechy_student_details which is given below:
- We need to get the id, age, and city values of each student from the relation wikitechy_student_details and store it into another relation named foreach_data which is given below: