pig tutorial - apache pig tutorial - Apache Pig - GetMinute(datetime) Function - pig latin - apache pig - pig hadoop




What is GetMinute(datetime) Function in Apache Pig ?

  • TheGetMinute(datetime) function will accept a date-time object as parameter and will return the minute of the current hour of date-time object.
  • The GetMinutes(datetime) method returns the of the specified date and time
  • The GetMinute(datetime) functionextracts the minute portion as a string from the dtl value.

Syntax

grunt>GetMinute(datetime)

Example

  • Ensure that there is a file named wikitechy_date.txt in the HDFS directory /pig_data/ which is given below:
  • The file contains the date-of-birth details of a particular person, where it has the id, date, and time.

wikitechy_date.txt wikitechy_date.txt

131,1992/07/22 09:00:00
132,1994/04/18 10:22:00
133,1996/10/12 03:11:44 
  • We have loaded the file into Pig with a relation name called date_data which is given below:
grunt>date_data = LOAD 'hdfs://localhost:9000/pig_data/wikitechy_date.txt' USING PigStorage(',')
as (id:int,date:chararray);
  • This function will retrieve the minute of the hour from the given date-time object.
  • We need to generate the date-time objects of all the employees by using todate() function.
grunt>todate_data = foreachdate_data generate ToDate(date,'yyyy/MM/dd HH:mm:ss')
as (date_time:DateTime);	
grunt> Dump todate_data;
(1992-07-22T09:00:00.000+05:30) 
(1994-04-18T10:22:00.000+05:30) 
(1996-10-12T03:11:44.000+05:30)
  • We need to get the minutes from the birth time of each employee by using GetMinute() function and also store it in the relation name calledgetminute_data which is given below:
grunt>getminute_data = foreachtodate_data generate (date_time), GetMinute(date time _);

Verification

  • We need to verify the contents of the getminute_data relation by using the Dump operator which is given below:
grunt> Dump getminute_data;	

Output:

  • The above statement stores in the relation named getminute_data
(1992-07-22T09:00:00.000+05:30,0) 
(1994-04-18T10:22:00.000+05:30,22) 
(1996-10-10T03:11:44.000+05:30,11) 

Related Searches to Apache Pig - GetMinute(datetime) Function