Home » Apache Pig COUNT Function

Apache Pig COUNT Function

by Online Tutorials Library

Apache Pig COUNT Function

The Apache Pig COUNT function is used to count the number of elements in a bag. It requires a preceding GROUP ALL statement for global counts and a GROUP BY statement for group counts. It ignores the null values.

Example of COUNT Function

In this example, we count the tuples in the bag.

Steps to execute COUNT Function

  • Create a text file in your local machine and insert the list of tuples.

Apache Pig COUNT Function

  • Check the tuples inserted in the text files.

Apache Pig COUNT Function

  • Upload the text files on HDFS in the specific directory.
  • Open the pig MapReduce run mode.
  • Load the file that contains the data.
  • Now, execute and verify the data.

Apache Pig COUNT Function

  • Let’s group the data on the basis of ‘a1’ field.

Apache Pig COUNT Function

  • Let’s return the count of given tuples.

Apache Pig COUNT Function

Here, we got the desired output.

Next TopicIN Function

You may also like