0

Can someone give a full example of date time functions including the 'register' jar ? I have been trying to get CurrentTime() and ToDate() running without much success. I have the piggybank jar in classpath and registered the same. But it always says the function has to be defined before usage. I read this question comparing datetime in pig before this.

Community
  • 1
  • 1
Antei
  • 39
  • 7

1 Answers1

1

Datetime functions can be easily implemented using native pig, you no need to go for piggybank jar.

Example:
In this example i will read set of dates from the input file, get the current datetime and calculate the total no of days between previous and current date

input.txt

2014-10-12T10:20:47
2014-08-12T10:20:47
2014-07-12T10:20:47

PigScript:

A = LOAD 'input.txt' AS (mydate:chararray);
B = FOREACH A GENERATE ToDate(mydate) AS prevDate,CurrentTime() AS currentDate,DaysBetween(CurrentTime(),ToDate(mydate)) AS diffDays;
DUMP B;

Output:

(2014-10-12T10:20:47.000+05:30, 2014-12-12T10:39:15.455+05:30, 61)
(2014-08-12T10:20:47.000+05:30, 2014-12-12T10:39:15.455+05:30, 122)
(2014-07-12T10:20:47.000+05:30, 2014-12-12T10:39:15.455+05:30, 153)

You can refer few examples from my old post
Human readable String date converted to date using Pig?
Storing Date and Time In PIG
how to convert UTC time to IST using pig

Community
  • 1
  • 1
Sivasakthi Jayaraman
  • 4,724
  • 3
  • 17
  • 27