pig tutorial - apache pig tutorial - Apache Pig AVG() Function - pig latin - apache pig - pig hadoop
What is AVG() Function in Apache Pig ?
- The AVG() function which is used in Apache Pig returns the average value of the numeric columns which is done in a bag.
- The AVG() function is done to compute the average of the numerical values which is done within a bag.
- The AVG() function will ignore the NULL values while we are calculating the average values
- The AVG() Function computes the numeric values within a single-column bag.
- The AVG() function will require a preceding GROUP ALL statement for global averages and the GROUP BY statement for the group averages. which is given in the average function
Learn Apache Pig - Apache Pig tutorial - Apache Pig AVG() - Apache Pig examples - Apache Pig programs
Learn Apache Pig - Apache Pig tutorial - Apache Pig AVG() Function - Apache Pig examples - Apache Pig programs
Syntax
Example
wikitechy_employee_details.txt
- And hence we have loaded this file into Pig which is done with the relation name wikitechy_employee_details as shown below.
Calculating the Average GPA
- Let us group the relation wikitechy_employee_details by using the Group All operator, and store the result in the relation which is called employee_group_all which is given below:
- This statement which is given above will produce a relation for employee_group_all as shown below.
- We will now calculate the global average GPA of all the employees by using the AVG() function which is given below: