pig tutorial - apache pig tutorial - Apache Pig - MinutesBetween(datetime1, datetime2) Function - pig latin - apache pig - pig hadoop



What is MinutesBetween(datetime1, datetime2) Function in Apache Pig ?

  • The function MinuteBetween(datetime1,datetime2) accept two date-time objects and will calculates the number of minutes which are given between the two given date-time objects.
  • The function MinutesBetween(datetime1,datetime2) returns the number of minutes which is given between two specified datetime values.
  • The function MinutesBetween(datetime1,datetime2) will always return the positive result and the parameter values which are interchangeable.

Syntax

grunt>MinutesBetween(datetime1, datetime2)

Example

  • Ensure that we have a file named wikitechy_doj_dob.txt in the HDFS directory /pig_data/.
  • The file contains the date-of-birth details and date-of-joining details of a particular person, id, dateof-birth, and date-of-joining.

wikitechy_doj_dob.txt

121,26/09/1989 09:00:00,16/01/2015 09:00:00
122,20/06/1980 10:22:00,10/08/2011 09:00:00
123,19/12/1990 03:11:44,25/10/2012 09:00:00 
  • We have loaded the file into Pig with a relation name called doj_dob_data which is given below.
doj_dob_data = LOAD 'hdfs://localhost:9000/pig_data/wikitechy_doj_dob.txt' USING PigStorage(',')
as (id:int, dob:chararray, doj:chararray);
  • We need to calculate the number of minutes between date-of-birth and date-of-joining of the employees by using the MinutesBetween() function which is given below:
grunt>minutesbetween_data = foreachdoj_dob_data generate
MinutesBetween(ToDate(doj,'dd/MM/yyyy HH:mm:ss'),ToDate(dob,'dd/MM/yyyy HH:mm:ss'));

Verification

  • We need to verify the contents of the relation using the Dump operator as shown below.
grunt> Dump minutesbetween_data;

Output:

  • The above statement stores the result in the relation named minutesbetween_data.
(13309920)
(16377038)
(11492988) 

Related Searches to Apache Pig GetMilliSecond(datetime) Function