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.




  • 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.


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;
  • 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);


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


  • The above statement stores in the relation named getmillisecond_data

Related Searches to Apache Pig GetMilliSecond(datetime) Function

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add wikitechy.com to your ad blocking whitelist or disable your adblocking software.