pig tutorial - apache pig tutorial - Apache Pig - ToDate(milliseconds) Function - pig latin - apache pig - pig hadoop




What is ToDate(milliseconds) Function in Apache Pig ?

  • The ToDate(milliseconds) function will generate a DateTime object which is done according to the given parameters which is given in the function.
  • The ToDate(milliseconds) function uses scalars as parameters which is done in the ToDate(milliseconds)function
  • ToDate(milliseconds) function converts the ISO or the customized string or the Unix timestamp to the DateTime object.

Syntax

grunt> ToDate(milliseconds)
grunt> ToDate(iosstring) 
grunt> ToDate(userstring, format) 
grunt> ToDate(userstring, format, timezone)

Example

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

wikitechy_date.txt

101,1995/07/25 09:00:00
102,1999/05/12 10:22:00
103,1997/10/17 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);
  • Now you can calculate the DateTime object which is corresponding to the date-of-birth of the employee.
grunt> todate_data = foreach date_data generate ToDate(date,'yyyy/MM/dd HH:mm:ss')
as (date_time:DateTime >);

Verification

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

Output

  • The above statement stores the result in the relation named todate_data.
(1995-07-25T09:00:00.000+05:30)
(1999-05-12T10:22:00.000+05:30)
(1997-10-17T03:11:44.000+05:30)

Related Searches to Apache Pig - ToDate(milliseconds) 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.

×