pig tutorial - apache pig tutorial - Apache Pig COUNTSTAR() Function - pig latin - apache pig - pig hadoop
What is COUNT_STAR() function in Apache Pig ?
- The COUNT_STAR() function used in Apache Pig is similar to the COUNT() function.
- While counting the elements, the COUNT_STAR() function includes the NULL values while counting the elements.
- COUNT_STAR function is used to compute the number of elements in a bag.
- COUNT_STAR function requires a preceding GROUP ALL statement for global counts and also a GROUP BY statement for group counts.
- COUNT_STAR will generate the count of the values of the first field which is given in a tuple.
Syntax
Example
wikitechy_employee_details.txt
- We have loaded the file into Pig with the relation which is called wikitechy_employee_details which is given below
Calculating the Number of Tuples
- We need to group the relation wikitechy_employee_details by using the Group All operator, and also we need to store the result in the relation name employee_group_all which is given below:
- It will produce a relation which is using DUMP employee which is given below:
- We need to calculate the number of tuples and records which is given in the relation.