Apache Pig - GetMinute()



This function accepts a date-time object as parameter and returns the minute of the current hour of a given date-time object.

Syntax

Here is the syntax of the GetMinute() function.

grunt> GetMinute(datetime)

Example

Assume that there is a file named date.txt in the HDFS directory /pig_data/ as shown below. This file contains the date-of-birth details of a particular person, id, date, and time.

date.txt

001,1989/09/26 09:00:00
002,1980/06/20 10:22:00
003,1990/12/19 03:11:44 

And, we have loaded this file into Pig with a relation named date_data as shown below.

grunt> date_data = LOAD 'hdfs://localhost:9000/pig_data/date.txt' USING PigStorage(',')
   as (id:int,date:chararray);

Following is an example of the GetMinute() function. The GetMinute() function will retrive the minute of the hour from the given date-time object. Therefore, first of all, let’s generate the date-time objects of all employees using todate() function.

grunt> todate_data = foreach date_data generate ToDate(date,'yyyy/MM/dd HH:mm:ss')
   as (date_time:DateTime );

grunt> Dump todate_data;
(1989-09-26T09:00:00.000+05:30) 
(1980-06-20T10:22:00.000+05:30) 
(1990-12-19T03:11:44.000+05:30)

Now, let’s get the minutes from the birth time of each employee using GetMinute() and store it in the relation named getminute_data as shown below.

grunt> getminute_data = foreach todate_data generate (date_time), GetMinute(date_time);

Now verify the contents of the getminute_data relation using the Dump operator as shown below.

grunt> Dump getminute_data;
  
(1989-09-26T09:00:00.000+05:30,0) 
(1980-06-20T10:22:00.000+05:30,22) 
(1990-12-19T03:11:44.000+05:30,11) 
apache_pig_date_time_functions.htm
Advertisements