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



What is GetMilliSeconds(datetime) Function in Apache Pig ?

  • The GetMiliSeconds(datetime) function will accept a date-time object as a parameter and will returns the milliseconds of the current second of date-time object.
  • The GetMilliSeconds() method returns the milliseconds (from 0 to 999) of the specified date and time.
  • The GetMilliSeconds() gets the milliseconds component of the date which is represented by this instance.

Syntax

grunt>GetMilliSecond(datetime)

Example

  • Ensure that we have a file name 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 person id, date and time.

wikitechy_date.txt

121,1991/08/22 09:00:00
122,1995/07/25 10:22:00
123,1999/10/27 03:11:44 
  • We have loaded this 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);
  • The function will retrieve the milliseconds of the current second from the date-time object.
  • We need to generate the date-time objects of all the employees using by todate() function which is given below:
grunt>todate_data = foreachdate_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)
  • We need to get the seconds from the birth time of each employee by using GetMilliSecond() function and store it in the relation called getmillisecond_data which is given below:
grunt>getmillisecond_data = foreachtodate_data generate (date_time), GetMilliSecond(date_time);

Verification

  • We need to verify the contents of the getmillisecond_datarelation by using Dump operator which is given below.
grunt> Dump getmillisecond_data;

Output:

  • The above statement stores in the relation named getmillisecond_data
(1991-08-22T09:00:00.000+05:30,0)
(1995-07-25T10:22:00.000+05:30,0)
(1999-10-27T03:11:44.000+05:30,0) 


Related Searches to Apache Pig GetMilliSecond(datetime) Function