pig tutorial - apache pig tutorial - Apache Pig - MAX() Function - pig latin - apache pig - pig hadoop

What is Max() function?

  • MAX() function is used to calculate the highest value for a column in a single-column bag
  • The Max() function will ignores the NULL values while calculating the maximum value
  • The Max() function will return the maximum value in a set of values.
  • MAX() requires a preceding GROUP ALL statement for global maximums and a GROUP BY statement for group maximums.
  • The MAX() function is a built-in function which can be called as Statistical Function.
 max function in apache pig

Learn apache pig - apache pig tutorial - max function in apache pig - apache pig examples - apache pig programs


grunt> Max(expression)



  • We have loaded this file into Pig with the relation name called wikitechy_employee_details which is given below:
grunt> wikitechy_employee_details = LOAD 'hdfs://localhost:9000/pig_data/wikitechy_employee_details.txt' USING PigStorage(',')
   as (id:int, firstname:chararray, lastname:chararray, age:int, phone:chararray, city:chararray, gpa:int);

Calculating the Maximum GPA

  • We need to group the relation wikitechy_employee_details using the Group All operator, and we need to store the result in the relation called employee_group_all which is given below:
grunt> employee_group_all = Group wikitechy_employee_details All;

This will produce a relation for calculating the maximum GPA as shown below.

grunt> Dump employee_group_all;
(7,Kamal,Nayak,24,9848022 334,trivendram,83),
(5,Sruthi,Mohan thy,23,9848022336,Bhuwaneshwar,75),
(2,Ramesh,Battacharya,22,9848022338,Ko lkata,78),
  • Now, we will calculate the global maximum of GPA, of all the employees which is done using the MAX() function which is shown below.
grunt> employee_gpa_max = foreach employee_group_all  Generate
(wikitechy_employee_details.firstname,wikitechy_employee_details.gpa), MAX(wikitechy_employee_details.gpa);


grunt> Dump employee_gpa_max;


(({(Vanitha),(Kamal),(Keerthana),(Sruthi),(Preethi),(Harish),(Ramesh),(Suresh) } , 
    {    (72)    ,   (83),     (87)   ,    (75)   ,   (93)   ,   (90)   ,     (78)   , (89)    }), 93)

Related Searches to Apache Pig - MAX() Function

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add wikitechy.com to your ad blocking whitelist or disable your adblocking software.