Tuesday, July 19, 2016

Dates with AM/PM in Pig

I recently came across a question regarding converting date with AM/PM to a 24-hr format using Apache Pig.It took a while to figure out the format.Below is the sample data,script and the output.
INPUT
30/06/2016 02:43:23.324 PM
01/12/2016 12:43:23.324 AM
21/08/2016 06:43:23.324 PM
13/07/2016 12:43:23.324 AM
SCRIPT
A = LOAD 'test4.txt' AS (create_dt:chararray);
B = FOREACH A GENERATE ToDate(create_dt,'dd/MM/yyyy hh:mm:ss.SSS aa') AS create_dt;
DUMP B;
OUTPUT