Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Threaded View
Pig, mail # user - Date Function in Pig


Copy link to this message
-
Re: Date Function in Pig
Serega Sheypak 2013-08-26, 15:43
You can use REGEX_EXTRACT with appropriate pattern and dummy ternary
operator
or
write dummy jython UDF using java/jython classes for Datetime conversion
or
You can convert it to unix seconds using "native pig" and sort as integers:

dataWithSeconds = FOREACH dataWithddMMMyyyy GENERATE
                                                (int)(SecondsBetween(ToDate(
ddMMMyyyy_field,               'ddMMMyyyy'),

        ToDate('1970-01-01 00:00:00',   'yyyy-MM-dd HH:mm:ss'))
                                                       ) as seconds;

ordered = ORDER dataWithSeconds by seconds;

2013/8/26 Ambastha, Abhishek <[EMAIL PROTECTED]>

> Hi,
>
> I have columns defined as string where dates are in the format ddMMMyyyy
> (e.g. 01JAN2009). I would like to sort this column in ascending order. For
> that, I need to convert string into date in the format 'ddMMMyyyy'.
>
> Please suggest how to do this.
>
> Regards,
> Abhishek
>