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

What is MIN Function in Apache Pig ?

    • The MIN() function used in Apache Pig is used to get the minimum value for a certain column in a single-column bag
    • The MIN() function will ignore the NULL values while calculating the minimum values
    • The MIN() function will requires a preceding GROUP ALL statement for the global minimums and a GROUP BY statement for the group minimums.
    • The MIN() function return the minimum value which is given in a set of values and also will return the smallest value of the column which is given in the table.
    • The MIN() function will return the smallest numeric value in a range of values and it will ignores the empty cells.

    Learn apache-pig - apache-pig tutorial - - apache-pig examples - apache-pig programs


      grunt> MIN(expression)



          • We have loaded this file into Pig with the relation name 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 Minimum GPA

            • We can group the relation wikitechy_employee_details by using the Group All operator, and we can store the result in the relation called employee_group_all which is given below
            grunt> employee_group_all = Group wikitechy_employee_details All;
            • It will produce a relation for calculating the minimum gpa as shown below.
            <b>grunt> Dump employee_group_all;</b>
            (7,Kamal,Nayak,24,9848022 334,trivendram,83),
            (5,Sruthi,Mohan thy,23,9848022336,Bhuwaneshwar,75),
            (3 ,Ramesh,Khanna,22,9848022339,Delhi,90),
            (2,sabrina,Battacharya,22,9848022338,Ko lkata,78),
            • Now, we need to calculate the global minimum of GPA, of all the employees by using the MIN() function which is given below:
            grunt> employee_gpa_min = foreach employee_group_all  Generate
               (employee_details.firstname, wikitechy_employee_details.gpa), MIN(wikitechy_employee_details.gpa);


              grunt> Dump employee_gpa_min;


                (({(Sharath),(Kamal),(Vanitha),(Sruthi),(Preethi),(Ramesh),(sabrina),(Guru) } , 
                   {    (72)    ,   (83)  ,     (87)   ,    (75)   ,   (93)   ,   (90)   ,     (78)   ,  (89)    }) ,72)

                Related Searches to Apache Pig - MIN() Function